Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: set application/css-sourcemap+json default charset to unicode #764

Merged
merged 3 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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