Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
**Master**

- Escape URI delimiters inside asset paths and query values. [Oskar Eichler](https://github.com/OskarEichler)

Get upgrade notes from Sprockets 3.x to 4.x at https://github.com/rails/sprockets/blob/master/UPGRADING.md

# 4.4.1
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -714,3 +714,5 @@ Please see the [CHANGELOG](https://github.com/rails/sprockets/tree/master/CHANGE

## License
Sprockets is released under the [MIT License](MIT-LICENSE).

Asset filenames containing `?`, `[` or `]` and query values containing `&` are escaped as components, preserving existing plus, slash and percent handling.
9 changes: 7 additions & 2 deletions lib/sprockets/uri_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ module URIUtils
URI_PARSER = defined?(URI::RFC2396_PARSER) ? URI::RFC2396_PARSER : URI::Generic::DEFAULT_PARSER
private_constant :URI_PARSER

# The URI parser character set, excluding component delimiters.
URI_PATH_UNSAFE = /[^\-_.!~*'()a-zA-Z\d;\/:@&=+$,]/
URI_QUERY_UNSAFE = /[^\-_.!~*'()a-zA-Z\d;\/?:@=+$,\[\]]/
private_constant :URI_PATH_UNSAFE, :URI_QUERY_UNSAFE

# Internal: Parse URI into component parts.
#
# uri - String uri
Expand Down Expand Up @@ -66,7 +71,7 @@ def join_file_uri(scheme, host, path, query)
str = +"#{scheme}://"
str << host if host
path = "/#{path}" unless path.start_with?("/".freeze)
str << URI_PARSER.escape(path)
str << URI_PARSER.escape(path, URI_PATH_UNSAFE)
str << "?#{query}" if query
str
end
Expand Down Expand Up @@ -165,7 +170,7 @@ def encode_uri_query_params(params)
when Integer
query << "#{key}=#{value}"
when String, Symbol
query << "#{key}=#{URI_PARSER.escape(value.to_s)}"
query << "#{key}=#{URI_PARSER.escape(value.to_s, URI_QUERY_UNSAFE)}"
when TrueClass
query << "#{key}"
when FalseClass, NilClass
Expand Down