Skip to content

Commit

Permalink
Merge pull request #764 from chadlwilson/fix-css-sourcemap-default-ch…
Browse files Browse the repository at this point in the history
…arset

fix: set application/css-sourcemap+json default charset to unicode
  • Loading branch information
rafaelfranca committed Sep 5, 2023
2 parents 42f7d5e + 572235a commit 5d26375
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
5 changes: 5 additions & 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)
- Fix compatibility with Rack 2 applications. [#790](https://github.com/rails/sprockets/pull/790)

## 4.2.0
Expand All @@ -13,6 +14,10 @@ Get upgrade notes from Sprockets 3.x to 4.x at https://github.com/rails/sprocket
- Make `Sprockets::Utils.module_include` thread safe on JRuby. [#759](https://github.com/rails/sprockets/pull/759)
- Fix typo in `asset.rb` file. [#768](https://github.com/rails/sprockets/pull/768)

## 4.1.1

- Fix `Sprockets::Server` to return response headers to be compatible with Rack::Lint 2.0.

## 4.1.0

- Allow age to be altered in asset:clean rake task.
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 5d26375

Please sign in to comment.