Skip to content

Commit

Permalink
Set application/css-sourcemap+json charset to unicode
Browse files Browse the repository at this point in the history
  • Loading branch information
chadlwilson committed Jul 3, 2023
1 parent c469001 commit ed0404e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Get upgrade notes from Sprockets 3.x to 4.x at https://github.com/rails/sprockets/blob/master/UPGRADING.md

- Fix for precompile issues when multiple extensions map to the same MIME type (eg. `.jpeg` / `.jpg`). [#781](https://github.com/rails/sprockets/pull/781)
- Fix `application/css-sourcemap+json` charset [#764](https://github.com/rails/sprockets/pull/764)

## 4.2.0

Expand Down
2 changes: 1 addition & 1 deletion lib/sprockets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ module Sprockets

require 'sprockets/source_map_processor'
register_mime_type 'application/js-sourcemap+json', extensions: ['.js.map'], charset: :unicode
register_mime_type 'application/css-sourcemap+json', extensions: ['.css.map']
register_mime_type 'application/css-sourcemap+json', extensions: ['.css.map'], charset: :unicode
register_transformer 'application/javascript', 'application/js-sourcemap+json', SourceMapProcessor
register_transformer 'text/css', 'application/css-sourcemap+json', SourceMapProcessor

Expand Down
13 changes: 12 additions & 1 deletion test/test_source_maps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def get_sources(map)
], get_sources(map)
end

test "reads the data transcoded to UTF-8" do
test "reads js data transcoded to UTF-8" do
processor = Proc.new do |input|
assert_equal Encoding::UTF_8, input[:data].encoding
{ data: input[:data] }
Expand All @@ -71,6 +71,17 @@ def get_sources(map)
@env.unregister_preprocessor('application/javascript', processor)
end

test "reads css data transcoded to UTF-8" do
processor = Proc.new do |input|
assert_equal Encoding::UTF_8, input[:data].encoding
{ data: input[:data] }
end
@env.register_processor('text/css', processor)
assert asset = @env.find_asset('sass/precompiled/main.css', pipeline: :debug)
ensure
@env.unregister_preprocessor('text/css', processor)
end

test "builds a minified source map" do
@env.js_compressor = Sprockets::UglifierCompressor.new

Expand Down

0 comments on commit ed0404e

Please sign in to comment.