Skip to content

Commit

Permalink
Fix frozen string literal compatibility issues
Browse files Browse the repository at this point in the history
NB: the Sass tests are just skipped because that gem won't ever
be compatible.
  • Loading branch information
byroot committed Mar 28, 2024
1 parent f4218ad commit 35350e2
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/sprockets.rb
Expand Up @@ -105,7 +105,7 @@ module Sprockets
register_bundle_processor 'application/javascript', Bundle
register_bundle_processor 'text/css', Bundle

register_bundle_metadata_reducer '*/*', :data, proc { "" }, :concat
register_bundle_metadata_reducer '*/*', :data, proc { "" }, :+
register_bundle_metadata_reducer 'application/javascript', :data, proc { "" }, Utils.method(:concat_javascript_sources)
register_bundle_metadata_reducer '*/*', :links, :+

Expand Down
2 changes: 2 additions & 0 deletions lib/sprockets/directive_processor.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: false

require 'set'
require 'shellwords'

Expand Down
4 changes: 2 additions & 2 deletions lib/sprockets/server.rb
Expand Up @@ -251,11 +251,11 @@ def cache_headers(env, etag)
# If the request url contains a fingerprint, set a long
# expires on the response
if path_fingerprint(env["PATH_INFO"])
headers["Cache-Control"] << ", max-age=31536000"
headers["Cache-Control"] += ", max-age=31536000"

# Otherwise set `must-revalidate` since the asset could be modified.
else
headers["Cache-Control"] << ", must-revalidate"
headers["Cache-Control"] += ", must-revalidate"
headers["Vary"] = "Accept-Encoding"
end

Expand Down
1 change: 1 addition & 0 deletions lib/sprockets/utils.rb
Expand Up @@ -102,6 +102,7 @@ def string_end_with_semicolon?(str)
#
# Returns buf String.
def concat_javascript_sources(buf, source)
buf = +buf
if source.bytesize > 0
buf << source

Expand Down
2 changes: 2 additions & 0 deletions test/test_asset.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: false

require "sprockets_test"

module AssetTests
Expand Down
2 changes: 1 addition & 1 deletion test/test_digest_utils.rb
Expand Up @@ -35,7 +35,7 @@ def test_digest
assert_equal "62427aa539a0b78e90fd710dc0e15f2960771ba44214b5d41d4a93a8b2940a38", hexdigest({"foo" => "baz"})
assert_equal "b6054efd9929004bdd0a1c09eb2d12961325396da749143def3e9a4050aa703e", hexdigest([[:foo, 1]])
assert_equal "79a19ffe41ecebd5dc35e95363e0b4aa79b139a22bc650384df57eb09842f099", hexdigest([{:foo => 1}])
assert_equal "94ee40cca7c2c6d2a134033d2f5a31c488cad5d3dcc61a3dbb5e2a858635874b", hexdigest("foo".force_encoding('UTF-8').encoding)
assert_equal "94ee40cca7c2c6d2a134033d2f5a31c488cad5d3dcc61a3dbb5e2a858635874b", hexdigest(Encoding::UTF_8)

assert_raises(TypeError) do
digest(Object.new)
Expand Down
1 change: 1 addition & 0 deletions test/test_encoding.rb
@@ -1,4 +1,5 @@
# encoding: utf-8
# frozen_string_literal: false
require "sprockets_test"

class AssetEncodingTest < Sprockets::TestCase
Expand Down
2 changes: 2 additions & 0 deletions test/test_sass.rb
@@ -1,5 +1,7 @@
require 'sprockets_test'

return if "test".frozen? # The sass gem isn't frozen string literal compatible

silence_warnings do
require 'sass'
end
Expand Down

0 comments on commit 35350e2

Please sign in to comment.