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
Path with spaces throws a bad URI(is not URI?) error #687
Comments
Hello! Thanks for opening up an issue. In order to move forwards with this issue I'll need an example app that reproduces the behavior (https://www.codetriage.com/example_app). |
For anyone else who ends up here via Google I've got a workaround for now. This is a frustrating problem if you migrate code stored in a Dropbox to Dropbox business where it suddenly moves all files to a path that has spaces and you can't rename the files to exclude spaces. Nice one Dropbox - there's a thread about this total failure to consider customer use cases here Here's a simple but most likely not very nice hack to fix it if you've got a rails project
scheme, _, host, _, _, path, _, query, _ = URI.split(uri.gsub(' ', '%20'))
gem 'sprockets', git: 'https://github.com/github-username/sprockets.git', branch: '3.x' Not ideal but at least a way of making it work until there's a proper fix in sprockets for when your project is contained within a folder that has had spaces added in the pathname and you can't rename it because Dropbox thinks it's ok to have a path with a space in it if you suddenly pay them more than you used to. Go figure. |
This should be a general discussion about urlencoding path segments. For "reasons" I'm stuck with images that have You can reproduce this by generating any old rails project, create those 3 pngs and compare expectation to result. <% ["test1.png", "te st2.png", "te+st3.png"].each do |img| %>
<%= "valid" if URI.parse(image_url(img)) rescue "invalid" %><br>
<%= image_tag(img) %><br>
<% end -%> Whilst 1 and 2 will be displayed, 2 is not a valid URL and 3 won't display whilst being valid (+ essentially the same as %20 or a space) |
Expected behavior
When a Rails or Sprockets project is placed in a directory with spaces in the folder names in the path, it shouldn't throw any errors. It should just escape the path name and work like normal.
Actual behavior
Once you put your project in a folder that has spaces in the path name, it throws the following error:
System configuration
Example App (Reproduction)
I have successfully created a failing test on a fork of Sprockets. You can simply pull the following branch, run
bundle exec rake test
and you will see the failing test.This is what you should see:
Steps Taken To Begin Fixing
I have isolated the problem to the following method:
One solution I have tried is to essentially escape
uri
at the beginning of the method, so I inserted this line at the top of that method:The issue this creates is that it escapes paths that were previously escaped, e.g. the following test from
test/test_uri_utils.rb
has begun to fail with that fix:Primarily because it returns the original string as a URI, i.e.
file:///usr/local/bin/ruby%20on%20rails
, as opposed to the unescaped version.The reason this is the case is because the first thing it does is now escapes the previously escaped string and then unescapes that double escaped string, which reverts it to the original string.
There are also other Failures, Errors & Skips that this small change has created.
So rather than digging much further, I figured I would reach out for some help.
The text was updated successfully, but these errors were encountered: