-
Notifications
You must be signed in to change notification settings - Fork 13.6k
rustdoc layout template only emit crossorigin
when needed
#144467
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
base: master
Are you sure you want to change the base?
rustdoc layout template only emit crossorigin
when needed
#144467
Conversation
The `crossorigin` attribute may cause issues when the href is not actuall across origins. Specifically, the tag causes the browser to send a preflight OPTIONS request to the href even if it is same-origin. Some tempermental servers may reject all CORS preflect requests even if they're actually same-origin, which causes a CORS error and prevents the fonts from loading, even later on. This commit fixes that problem by not emitting `crossorigin` if the url looks like a domain-relative url.
rustbot has assigned @GuillaumeGomez. Use |
Seems ok to. Do you see any potential issue @notriddle? |
Co-authored-by: Guillaume Gomez <[email protected]>
/// Determines if [`Self::static_route_path`] is relative to the same origin. | ||
fn static_root_path_same_origin(&self) -> bool { | ||
(self.static_root_path.starts_with('/') && !self.static_root_path.starts_with("//")) | ||
|| self.static_root_path.starts_with(".") |
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.
it's worth noting that this does not accurately check if a url is relative, as something like module/index.html
is also relative.
these false negatives might not matter for fixing this bug, but it should probably be noted so noone tries to use this function for something it does matter for.
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.
Hmm good catch, I can try making it a little more robust
The
crossorigin
attribute may cause issues when the href is not actually cross-origin. Specifically, the tag causes the browser to send a preflight OPTIONS request to the server even if it is same-origin. Some temperamental servers may reject all CORS preflight requests even if they're actually same-origin, which causes a CORS error and prevents the fonts from loading, even later on.This commit fixes that problem by not emitting
crossorigin
if the url appears to be relative to the same origin.