-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: properly parse non-url encoded file specs #200
base: main
Are you sure you want to change the base?
Conversation
There still appears to be some incorrect behavior here, that was here even before this PR. > require('.')('/path/br[acket')
Result {
type: 'directory',
registry: undefined,
where: '/Users/wraithgar/Development/npm/npm-package-arg/branches/gar_path-url-encoding',
raw: '/path/br[acket',
rawSpec: '/path/br[acket',
saveSpec: 'file:/path/br[acket',
fetchSpec: '/path/br[acket',
gitRange: undefined,
gitCommittish: undefined,
gitSubdir: undefined,
hosted: undefined
}
> decodeURI('file:/path/br[acket')
'file:/path/br[acket' but some new characters that this now allows (like %) will:
I chose not to encode |
Still some |
3e28f1e
to
ce6c05b
Compare
|
||
const normalizePath = p => p && p.replace(/^[a-zA-Z]:/, '').replace(/\\/g, '/') | ||
|
||
const cwd = normalizePath(process.cwd()) | ||
process.cwd = () => cwd | ||
const normalizePaths = spec => { | ||
spec.saveSpec = normalizePath(spec.saveSpec) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was masking bugs.
Properly creates file package args that contain characters that need to be url encoded. There is also a refactor/cleanup in here - Removed the magic windows global for testing, fixing the tests to mock process.platform instead. - Moved inline regexes up to where the others are defined - Renamed a few variables to be more correct (i.e. isFilename to isFileType) - Refactored Result to be a proper Class instead of a function w/ prototypes Closes: #193
ce6c05b
to
3c876a6
Compare
return isWindowsFile.test(spec) | ||
} | ||
// We never hit this in windows tests, obviously | ||
/* istanbul ignore next */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fact that this was covered before is concerning.
Properly creates file package args that contain characters that need to be url encoded.
There is also a refactor/cleanup in here
Closes: #193