diff --git a/lib/remote_input.rb b/lib/remote_input.rb index b0fe0e9..122d597 100644 --- a/lib/remote_input.rb +++ b/lib/remote_input.rb @@ -56,10 +56,17 @@ def path def cache_path return @cache_path if @cache_path dirname = File.dirname(normalize_path).delete_suffix("/") - cache_id = "#{@url.host}#{dirname}".tr("/", "-") + cache_id = to_cache_id("#{@url.host}#{dirname}") + query = @url.query + cache_id += "+#{to_cache_id(query)}" if query and not query.empty? @cache_path = CachePath.new(cache_id) end + def to_cache_id(s) + allow_list = "0-9A-Za-z._~=-" + s.tr("^#{allow_list}", "-") + end + def normalize_path url_path = @url.path url_path = "/" if url_path.empty? diff --git a/test/test-remote-input.rb b/test/test-remote-input.rb index 0b71b3a..d115aa7 100644 --- a/test/test-remote-input.rb +++ b/test/test-remote-input.rb @@ -61,7 +61,7 @@ def test_open_with_block_raised data("no path", ["/example.com/data", "https://example.com"]) data("root", ["/example.com/data", "https://example.com/"]) data("file", ["/example.com/file", "https://example.com/file"]) - data("query", ["/example.com/file", "https://example.com/file?a=b"]) + data("query", ["/example.com+a=-/file", "https://example.com/file?a=+"]) data("directory", ["/example.com-a/data", "https://example.com/a/"]) data("nested file", ["/example.com-a/file", "https://example.com/a/file"]) data("deeply nested", ["/example.com-a-b/file", "https://example.com/a/b/file"])