-
Notifications
You must be signed in to change notification settings - Fork 30
Fix: wrong load external resources when the local protocol is file:// #309
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: wrong load external resources when the local protocol is file:// #309
Conversation
src/core/lib/utils.ts
Outdated
| // handle local file imports if the url isn't remote resource or data blob | ||
| if ( | ||
| self.location.protocol === 'file:' && | ||
| !EXTERNAL_REGEX_URL.test(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.
Looks like all cases could be a single regex, if you just test /^(data|https?|ftps?):/
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.
And TBH, you could simplify further by just checking whether it looks like {protocol}:
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.
@elsassph Thanks, I fixed it! Simplify as {protocol}:
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.
Cool, I thought it might be simpler/safer to not test the protocol itself, e.g. any ^[a-z]+: is a protocol.
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.
@elsassph I prefer to have a more specific check based on protocol resources.
IMO your suggestion is too generic.
What happen if you have an local image with filename like aaa:2222.png?
wouterlucas
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.
Good catch 😅 thanks! 😄
When an external image resource is loaded from https, the function convertUrlToAbsolute inside the utils.ts doesn't check if it is a network or internal resource.