-
Notifications
You must be signed in to change notification settings - Fork 799
Fix: Path with spaces throws a bad URI(is not URI?) error #689
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: main
Are you sure you want to change the base?
Changes from 6 commits
bf58f04
a0dccbd
7042228
36751bd
6b2e2b4
be3b7c7
eba2602
7d428a1
2284a28
e975f8e
19c8a8f
d9e171d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,13 +37,25 @@ def join_uri(scheme, userinfo, host, port, registry, path, opaque, query, fragme | |
| URI::Generic.new(scheme, userinfo, host, port, registry, path, opaque, query, fragment).to_s | ||
| end | ||
|
|
||
| # Escaped URI: Return URI regardless of whether the string is initially escaped. | ||
| # If the initial URI is escaped, then that gets returned. If not, then it is escaped. | ||
| # | ||
| # uri - String uri | ||
| # | ||
| # Returns uri | ||
marcamillion marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| def escaped_uri(uri) | ||
marcamillion marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return uri if uri == URI::Generic::DEFAULT_PARSER.escape(URI::Generic::DEFAULT_PARSER.unescape(uri)) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any case were this method receives an already escaped uri? The URIs are usually generated by the library, so we should be able to know when we are passing a escaped uri and in that case not call this method at all. Always doing this check will be expensive. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, keep in mind that I added this new I do know though, that the For example, this line unescapes the So I assume someone had seen some URIs sent to that Another instance is there is a test case that includes already escaped URIs sent to Does that fully address your question? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it does. Sprockets is the library that generates those URI, so we can make sure we either only accept escaped URIs on this method or we only accept unescaped URIs. So the fix seems to be to make sure we only pass escaped URIs to That way we don't need to check if the path was already escaped and we can be sure the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Exactly, that's exactly what this method does. Previously, it was assumed that the URI was escaped -- which based on the linked issue I ran into -- wasn't always the case. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So is it ready to be merged? Also, this is my first time doing a PR on any Rails project, so out of curiosity, how will multiple versions be handled? As in, Sprockets seems to be frozen at Will this fix be automatically applied to The reason I am asking is that this PR was done on the latest I tried to run the test suite on branch I have tested my version of this fix in my local So I am trying to think through and figure out how to get both of them working as easily as possible. Thoughts? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you know the URI that fails you can do something like We need the real codepath in an application, not the codepath of the test suite. You could try to run your application that you know you can reproduce the bug against your local sprockets and see what exactly is passing an unescaped URI to that method. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Not sure if this is the codepath you are looking for, but if I simply remove the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Ok below is the full stack trace from the application where it fails. I assume you just need the Let me know if I still need to do your other suggestion because this doesn't fully capture it. Edit 1 The application fails at the
This is the error:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bump @rafaelfranca There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hey @rafaelfranca I know you are prolly busy with a bunch of other stuff, and we don't need to solve this completely right now. But I would love to get my app working. If I use my fork, with my fixes, in my I tried pulling the Do you have any suggestions for how I might get around this to get my app working again by any chance? It's been out of commission for more than 2 weeks, so any assistance you can give me to get that operational would be greatly appreciated. Thanks. |
||
| URI::Generic::DEFAULT_PARSER.escape(uri) | ||
| end | ||
|
|
||
| # Internal: Parse file: URI into component parts. | ||
| # | ||
| # uri - String uri | ||
| # | ||
| # Returns [scheme, host, path, query]. | ||
| def split_file_uri(uri) | ||
| scheme, _, host, _, _, path, _, query, _ = URI.split(uri) | ||
| # We need to ensure that the URI being split is always escaped | ||
marcamillion marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| scheme, _, host, _, _, path, _, query, _ = URI.split(escaped_uri(uri)) | ||
marcamillion marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| path = URI::Generic::DEFAULT_PARSER.unescape(path) | ||
| path.force_encoding(Encoding::UTF_8) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.