-
-
Notifications
You must be signed in to change notification settings - Fork 495
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
Add support for relative protocols in url filter #1276
Conversation
This looks good to me. Although it's also potentially a breaking change for some people. I think we'd need to document and communicate this change thoroughly. @zachleat this is slightly off topic but it would be super useful if the website documentation was in the same repo as eleventy (possibility even a monorepo (...I know, I know, but you can do it with a light touch, it's not all bad!)) I also think using changeset could be a good addition to managing things: https://github.com/atlassian/changesets. Let me know if you'd be open to PRs for either of these. |
// work with undefined | ||
url = url || ""; | ||
|
||
if ( | ||
validUrl.isUri(url) || | ||
url.indexOf("http://") === 0 || | ||
url.indexOf("https://") === 0 | ||
url.indexOf("https://") === 0 || | ||
(url.indexOf("//") === 0 && url !== "//") |
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 could also be written as (url.startsWith("//") && url !== "//")
Actually all of them in the conditional can be replaced with startsWith()
as there is no way the url to contain the protocol in any other position except the... start of the string
I think it should be mentioned that protocol relative URLs can be harmful, and are now considered an anti-pattern: |
This will ship with 1.0 |
This PR fixes #1247
Currently, the url filter normalize values starting with
//
as if they where paths, so for example a url to//example.com
is changed to/example.com
(orpathPrefix/example.com
if there's a path prefix configured).But technically,
//example.com
is a perfectly valid url that should be resolved tohttp://example.com
orhttps://example.com
, depending of the protocol of the current document location.This PR fixes this problem. Note that this is a breaking change.