From bf58f04bd776ee72cdbbe010debbbe3a7df4e356 Mon Sep 17 00:00:00 2001 From: Marc Gayle Date: Mon, 29 Jun 2020 18:43:13 -0500 Subject: [PATCH 01/11] Added a successful failing test. --- Gemfile | 2 ++ lib/sprockets/uri_utils.rb | 3 +++ test/test_uri_utils.rb | 5 +++++ 3 files changed, 10 insertions(+) diff --git a/Gemfile b/Gemfile index 43ba651a8..77f994d45 100644 --- a/Gemfile +++ b/Gemfile @@ -2,3 +2,5 @@ source "https://rubygems.org" gemspec gem "rack", github: 'rack/rack' + +gem 'pry', '~> 0.13.1' diff --git a/lib/sprockets/uri_utils.rb b/lib/sprockets/uri_utils.rb index 57ab184d9..3a358cf22 100644 --- a/lib/sprockets/uri_utils.rb +++ b/lib/sprockets/uri_utils.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true require 'uri' +require 'pry' module Sprockets # Internal: Asset URI related parsing utilities. Mixed into Environment. @@ -43,6 +44,8 @@ def join_uri(scheme, userinfo, host, port, registry, path, opaque, query, fragme # # Returns [scheme, host, path, query]. def split_file_uri(uri) + # We need to parse out any potential spaces in the path + # uri = URI::Generic::DEFAULT_PARSER.escape(uri) scheme, _, host, _, _, path, _, query, _ = URI.split(uri) path = URI::Generic::DEFAULT_PARSER.unescape(path) diff --git a/test/test_uri_utils.rb b/test/test_uri_utils.rb index 8a0e2a5e3..a10441638 100644 --- a/test/test_uri_utils.rb +++ b/test/test_uri_utils.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require 'minitest/autorun' require 'sprockets/uri_utils' +require 'pry' class TestURIUtils < MiniTest::Test include Sprockets::URIUtils @@ -35,12 +36,16 @@ def test_inverse_uri_functions end def test_split_file_uri + parts = split_file_uri("file:///usr/Company Name Dropbox/local/bin/myapp/assets") + assert_equal ['file', nil, '/usr/Company Name Dropbox/local/bin/myapp/assets', nil], parts + parts = split_file_uri("file://localhost/etc/fstab") assert_equal ['file', 'localhost', '/etc/fstab', nil], parts parts = split_file_uri("file:///etc/fstab") assert_equal ['file', nil, '/etc/fstab', nil], parts + # binding.pry parts = split_file_uri("file:///usr/local/bin/ruby%20on%20rails") assert_equal ['file', nil, '/usr/local/bin/ruby on rails', nil], parts From a0dccbdab2baedb5897bea63c12fea9717649c3d Mon Sep 17 00:00:00 2001 From: Marc Gayle Date: Tue, 30 Jun 2020 12:20:18 -0500 Subject: [PATCH 02/11] Implemented an EscapedURI method that either returns the URI if it is escaped or escapes it. --- lib/sprockets/uri_utils.rb | 18 +++++++++++++++--- test/test_uri_utils.rb | 1 - 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/sprockets/uri_utils.rb b/lib/sprockets/uri_utils.rb index 3a358cf22..597bbf7fc 100644 --- a/lib/sprockets/uri_utils.rb +++ b/lib/sprockets/uri_utils.rb @@ -38,15 +38,27 @@ 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 + def escaped_uri(uri) + return uri if uri == URI::Generic::DEFAULT_PARSER.escape(URI::Generic::DEFAULT_PARSER.unescape(uri)) + 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) - # We need to parse out any potential spaces in the path - # uri = URI::Generic::DEFAULT_PARSER.escape(uri) - scheme, _, host, _, _, path, _, query, _ = URI.split(uri) + # scheme, _, host, _, _, path, _, query, _ = URI.split(uri) + + # We need to ensure that the URI being split is always escaped + scheme, _, host, _, _, path, _, query, _ = URI.split(escaped_uri(uri)) path = URI::Generic::DEFAULT_PARSER.unescape(path) path.force_encoding(Encoding::UTF_8) diff --git a/test/test_uri_utils.rb b/test/test_uri_utils.rb index a10441638..98dc2777a 100644 --- a/test/test_uri_utils.rb +++ b/test/test_uri_utils.rb @@ -45,7 +45,6 @@ def test_split_file_uri parts = split_file_uri("file:///etc/fstab") assert_equal ['file', nil, '/etc/fstab', nil], parts - # binding.pry parts = split_file_uri("file:///usr/local/bin/ruby%20on%20rails") assert_equal ['file', nil, '/usr/local/bin/ruby on rails', nil], parts From 704222807bf14deda1395b56950df0c62cd2e451 Mon Sep 17 00:00:00 2001 From: Marc Gayle Date: Fri, 3 Jul 2020 15:17:22 -0500 Subject: [PATCH 03/11] WIP: Attempting to fix Load URI with Index Alias error in Test Loader. --- lib/sprockets/uri_utils.rb | 1 - test/test_loader.rb | 2 ++ test/test_uri_utils.rb | 1 - 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/sprockets/uri_utils.rb b/lib/sprockets/uri_utils.rb index 597bbf7fc..508a65adf 100644 --- a/lib/sprockets/uri_utils.rb +++ b/lib/sprockets/uri_utils.rb @@ -1,6 +1,5 @@ # frozen_string_literal: true require 'uri' -require 'pry' module Sprockets # Internal: Asset URI related parsing utilities. Mixed into Environment. diff --git a/test/test_loader.rb b/test/test_loader.rb index d7bd9f14a..b65fa4178 100644 --- a/test/test_loader.rb +++ b/test/test_loader.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require 'sprockets_test' require 'pathname' +require 'pry' class TestLoader < Sprockets::TestCase def setup @@ -50,6 +51,7 @@ def setup test 'load uri with index alias' do filename = fixture_path('default/coffee/index.js') index_alias = fixture_path('default/coffee.js') + # binding.pry assert asset = @env.load("file://#{uri_path(filename)}?type=application/javascript&index_alias=#{Rack::Utils.escape(index_alias)}") assert_equal filename, asset.filename, asset.inspect assert_equal 'coffee.js', asset.logical_path, asset.inspect diff --git a/test/test_uri_utils.rb b/test/test_uri_utils.rb index 98dc2777a..aaf486afc 100644 --- a/test/test_uri_utils.rb +++ b/test/test_uri_utils.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true require 'minitest/autorun' require 'sprockets/uri_utils' -require 'pry' class TestURIUtils < MiniTest::Test include Sprockets::URIUtils From 36751bd3647e894b984d7d5f9798181d5ec22b2d Mon Sep 17 00:00:00 2001 From: Marc Gayle Date: Sun, 5 Jul 2020 22:08:21 -0500 Subject: [PATCH 04/11] Fixed the not loaded error being generated by the test suite. --- Gemfile | 2 -- test/test_loader.rb | 4 +--- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/Gemfile b/Gemfile index 77f994d45..43ba651a8 100644 --- a/Gemfile +++ b/Gemfile @@ -2,5 +2,3 @@ source "https://rubygems.org" gemspec gem "rack", github: 'rack/rack' - -gem 'pry', '~> 0.13.1' diff --git a/test/test_loader.rb b/test/test_loader.rb index b65fa4178..4093e9a22 100644 --- a/test/test_loader.rb +++ b/test/test_loader.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true require 'sprockets_test' require 'pathname' -require 'pry' class TestLoader < Sprockets::TestCase def setup @@ -51,8 +50,7 @@ def setup test 'load uri with index alias' do filename = fixture_path('default/coffee/index.js') index_alias = fixture_path('default/coffee.js') - # binding.pry - assert asset = @env.load("file://#{uri_path(filename)}?type=application/javascript&index_alias=#{Rack::Utils.escape(index_alias)}") + assert asset = @env.load("file://#{uri_path(filename)}?type=application/javascript&index_alias=#{index_alias}") assert_equal filename, asset.filename, asset.inspect assert_equal 'coffee.js', asset.logical_path, asset.inspect assert_equal fixture_path('default'), asset.to_hash[:load_path], asset.inspect From 6b2e2b419108b3f5d4ee95dd373c4cef49c8fe36 Mon Sep 17 00:00:00 2001 From: Marc Gayle Date: Sun, 5 Jul 2020 22:19:10 -0500 Subject: [PATCH 05/11] More tidying up debugging cruft. --- lib/sprockets/uri_utils.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/sprockets/uri_utils.rb b/lib/sprockets/uri_utils.rb index 508a65adf..461950be2 100644 --- a/lib/sprockets/uri_utils.rb +++ b/lib/sprockets/uri_utils.rb @@ -54,8 +54,6 @@ def escaped_uri(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 scheme, _, host, _, _, path, _, query, _ = URI.split(escaped_uri(uri)) From be3b7c7bad10a0401dfca00524c872286925ea9b Mon Sep 17 00:00:00 2001 From: Marc Gayle Date: Sun, 5 Jul 2020 22:44:38 -0500 Subject: [PATCH 06/11] Updated CHANGELOG. --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cd621e5cb..b27bd6960 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ Get upgrade notes from Sprockets 3.x to 4.x at https://github.com/rails/sprockets/blob/master/UPGRADING.md +## Next Release + +- Fix bug where project Path with spaces throws a bad URI(is not URI?) error - Marc Gayle - https://github.com/marcamillion + ## 4.0.2 - Fix `etag` and digest path compilation that were generating string with invalid digest since 4.0.1. From eba2602db3c406b2836dfcfe7b7ea6e112a9e438 Mon Sep 17 00:00:00 2001 From: Marc Gayle Date: Mon, 6 Jul 2020 15:40:17 -0500 Subject: [PATCH 07/11] Update lib/sprockets/uri_utils.rb MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Rafael França --- lib/sprockets/uri_utils.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/sprockets/uri_utils.rb b/lib/sprockets/uri_utils.rb index 461950be2..9204fce0a 100644 --- a/lib/sprockets/uri_utils.rb +++ b/lib/sprockets/uri_utils.rb @@ -54,7 +54,6 @@ def escaped_uri(uri) # # Returns [scheme, host, path, query]. def split_file_uri(uri) - # We need to ensure that the URI being split is always escaped scheme, _, host, _, _, path, _, query, _ = URI.split(escaped_uri(uri)) path = URI::Generic::DEFAULT_PARSER.unescape(path) From 7d428a12f8302d74c7a44e656aeff65b0a51b626 Mon Sep 17 00:00:00 2001 From: Marc Gayle Date: Mon, 6 Jul 2020 15:40:32 -0500 Subject: [PATCH 08/11] Update lib/sprockets/uri_utils.rb MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Rafael França --- lib/sprockets/uri_utils.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/sprockets/uri_utils.rb b/lib/sprockets/uri_utils.rb index 9204fce0a..08e58734c 100644 --- a/lib/sprockets/uri_utils.rb +++ b/lib/sprockets/uri_utils.rb @@ -42,7 +42,7 @@ def join_uri(scheme, userinfo, host, port, registry, path, opaque, query, fragme # # uri - String uri # - # Returns uri + # Returns String. def escaped_uri(uri) return uri if uri == URI::Generic::DEFAULT_PARSER.escape(URI::Generic::DEFAULT_PARSER.unescape(uri)) URI::Generic::DEFAULT_PARSER.escape(uri) From 2284a2830c4580f16f7d9a42162108c0b001d2fd Mon Sep 17 00:00:00 2001 From: Marc Gayle Date: Mon, 6 Jul 2020 15:40:39 -0500 Subject: [PATCH 09/11] Update lib/sprockets/uri_utils.rb MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Rafael França --- lib/sprockets/uri_utils.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/sprockets/uri_utils.rb b/lib/sprockets/uri_utils.rb index 08e58734c..bafec9ce4 100644 --- a/lib/sprockets/uri_utils.rb +++ b/lib/sprockets/uri_utils.rb @@ -37,8 +37,7 @@ 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. + # Internal: Escape the URI # # uri - String uri # From e975f8e2c62ba97976ff863e4359f2d9f7645946 Mon Sep 17 00:00:00 2001 From: Marc Gayle Date: Mon, 6 Jul 2020 15:40:49 -0500 Subject: [PATCH 10/11] Update lib/sprockets/uri_utils.rb MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Rafael França --- lib/sprockets/uri_utils.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/sprockets/uri_utils.rb b/lib/sprockets/uri_utils.rb index bafec9ce4..abfce60a3 100644 --- a/lib/sprockets/uri_utils.rb +++ b/lib/sprockets/uri_utils.rb @@ -42,7 +42,7 @@ def join_uri(scheme, userinfo, host, port, registry, path, opaque, query, fragme # uri - String uri # # Returns String. - def escaped_uri(uri) + def escape_uri(uri) return uri if uri == URI::Generic::DEFAULT_PARSER.escape(URI::Generic::DEFAULT_PARSER.unescape(uri)) URI::Generic::DEFAULT_PARSER.escape(uri) end From 19c8a8f5923f9f43230fb97764e7819e80900fbf Mon Sep 17 00:00:00 2001 From: Marc Gayle Date: Mon, 6 Jul 2020 15:40:57 -0500 Subject: [PATCH 11/11] Update lib/sprockets/uri_utils.rb MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Rafael França --- lib/sprockets/uri_utils.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/sprockets/uri_utils.rb b/lib/sprockets/uri_utils.rb index abfce60a3..ee540ab65 100644 --- a/lib/sprockets/uri_utils.rb +++ b/lib/sprockets/uri_utils.rb @@ -53,7 +53,7 @@ def escape_uri(uri) # # Returns [scheme, host, path, query]. def split_file_uri(uri) - scheme, _, host, _, _, path, _, query, _ = URI.split(escaped_uri(uri)) + scheme, _, host, _, _, path, _, query, _ = URI.split(escape_uri(uri)) path = URI::Generic::DEFAULT_PARSER.unescape(path) path.force_encoding(Encoding::UTF_8)