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)/

class << self
def call(input)
Expand Down
20 changes: 20 additions & 0 deletions test/test_sourcemapping_url_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,26 @@ def asset_path(path, options = {})
assert_equal({ data: "var mapped;\n//# sourceMappingURL=/assets/mapped-HEXGOESHERE.js.map\n//!\n" }, output)
end

def test_removing_path_prefix
@env.context_class.class_eval do
def resolve(path, **kargs)
if path == 'mapped.js.map'
"/assets/mapped.js.map"
else
raise Sprockets::FileNotFound
end
end

def asset_path(path, options = {})
"/assets/mapped-HEXGOESHERE.js.map"
end
end

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

def test_resolving_erroneously_without_map_extension
@env.context_class.class_eval do
def resolve(path, **kargs)
Expand Down