-
Notifications
You must be signed in to change notification settings - Fork 0
fix:add starting slash to file-urls #114
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
Conversation
digitalsadhu
left a comment
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.
I agree that how it currently works is a bit of a footgun. Have run into it myself. Interested to hear @trygve-lie thoughts.
| file(file = '') { | ||
| const base = this.base(); | ||
| let value; | ||
| if (base && ABSOLUTE_URL_REGEX.test(base)) { |
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.
Any reason not to use path.isAbsolute here?
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.
Just checked. isAbsolute is not doing the same thing as my test. my check is for an absolute URL, but path.isAbsolute checks for an absolute path. So isAbsolute('/test') is true but ABSOLUTE_URL_REGEX.test('/test') is false
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.
Ah good point.
|
An alternative solution to this problem is: |
|
I am fine with this. This did though get me to realize that we have more or less forgot to apply our common pattern for building paths and URL in this module. We try to strive for a pattern where each URL / path part always start with a We already have methods for this in the common package: https://github.com/eik-lib/common/blob/next/packages/utils/src/path-slashes.js If we followed this pattern we would end up with something like so; file(file = '') {
const sanitizedFile = utils.addLeadingSlash(file);
return new Asset({
value: `${this.base()}${sanitizedFile}`,
});
}In the above return value from Though; I think that is food for a second PR so I am fine with this. |
Currently we will receive a url without a slash delimiter if we pass inn a relative url to the file method without a starting slash. With this fix the URL is correct even if the starting slash is missing from the argument. It does not break any of the current tests, but we should consider if this is a breaking change.