Skip to content
Open
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: 1 addition & 1 deletion lib/sprockets/rails/sourcemapping_url_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Sprockets
module Rails
# Rewrites source mapping urls with the digested paths and protect against semicolon appending with a dummy comment line
class SourcemappingUrlProcessor
REGEX = /\/\/# sourceMappingURL=(.*\.map)/
REGEX = /\/\/# sourceMappingURL=(.*\.map\.?\w*)/

class << self
def call(input)
Expand Down
24 changes: 24 additions & 0 deletions test/test_sourcemapping_url_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,28 @@ def resolve(path, **kargs)
output = Sprockets::Rails::SourcemappingUrlProcessor.call(input)
assert_equal({ data: "var mapped;\n" }, output)
end

def test_missing_with_json_file_ext_also_removes_file_ext
@env.context_class.class_eval do
def resolve(path, **kargs)
raise Sprockets::FileNotFound
end
end

input = { environment: @env, data: "var mapped;\n//# sourceMappingURL=mappedNOT.js.map.json", name: 'mapped', filename: 'mapped.js', metadata: {} }
output = Sprockets::Rails::SourcemappingUrlProcessor.call(input)
assert_equal({ data: "var mapped;\n" }, output)
end

def test_missing_with_json_file_ext_and_subsequent_valid_js_retains_valid_js
@env.context_class.class_eval do
def resolve(path, **kargs)
raise Sprockets::FileNotFound
end
end

input = { environment: @env, data: "var mapped;\n//# sourceMappingURL=mappedNOT.js.map.json\nvar foo = bar();", name: 'mapped', filename: 'mapped.js', metadata: {} }
output = Sprockets::Rails::SourcemappingUrlProcessor.call(input)
assert_equal({ data: "var mapped;\n\nvar foo = bar();" }, output)
end
end