Skip to content

Commit 0aa9f7b

Browse files
committed
fix #4169: keep invalid source map URLs unmodified
1 parent 5959289 commit 0aa9f7b

File tree

5 files changed

+24
-12
lines changed

5 files changed

+24
-12
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
* Pass through invalid URLs in source maps unmodified ([#4169](https://github.com/evanw/esbuild/issues/4169))
6+
7+
This fixes a regression in version 0.25.0 where `sources` in source maps that form invalid URLs were not being passed through to the output. Version 0.25.0 changed the interpretation of `sources` from file paths to URLs, which means that URL parsing can now fail. Previously URLs that couldn't be parsed were replaced with the empty string. With this release, invalid URLs in `sources` should now be passed through unmodified.
8+
39
## 0.25.3
410

511
* Fix lowered `async` arrow functions before `super()` ([#4141](https://github.com/evanw/esbuild/issues/4141), [#4142](https://github.com/evanw/esbuild/pull/4142))

internal/bundler/bundler.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1616,6 +1616,7 @@ func (s *scanner) preprocessInjectedFiles() {
16161616
KeyPath: visitedKey,
16171617
PrettyPath: resolver.PrettyPath(s.fs, visitedKey),
16181618
IdentifierName: js_ast.EnsureValidIdentifier(visitedKey.Text),
1619+
Contents: define.Source.Contents,
16191620
}
16201621

16211622
// The first "len(InjectedDefine)" injected files intentionally line up

internal/js_parser/sourcemap_parser.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -342,14 +342,9 @@ func ParseSourceMap(log logger.Log, source logger.Source) *sourcemap.SourceMap {
342342
sourcePath := sourceURLPrefix + helpers.UTF16ToString(element.Value)
343343
sourceURL, err := url.Parse(sourcePath)
344344

345-
// Report URL parse errors (such as "%XY" being an invalid escape)
345+
// Ignore URL parse errors (such as "%XY" being an invalid escape)
346346
if err != nil {
347-
if urlErr, ok := err.(*url.Error); ok {
348-
err = urlErr.Err // Use the underlying error to reduce noise
349-
}
350-
log.AddID(logger.MsgID_SourceMap_InvalidSourceURL, logger.Warning, &tracker, source.RangeOfString(item.Loc),
351-
fmt.Sprintf("Invalid source URL: %s", err.Error()))
352-
sources = append(sources, "")
347+
sources = append(sources, sourcePath)
353348
continue
354349
}
355350

internal/logger/msg_ids.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ const (
6969

7070
// Source maps
7171
MsgID_SourceMap_InvalidSourceMappings
72-
MsgID_SourceMap_InvalidSourceURL
7372
MsgID_SourceMap_MissingSourceMap
7473
MsgID_SourceMap_UnsupportedSourceMapComment
7574

@@ -207,8 +206,6 @@ func StringToMsgIDs(str string, logLevel LogLevel, overrides map[MsgID]LogLevel)
207206
// Source maps
208207
case "invalid-source-mappings":
209208
overrides[MsgID_SourceMap_InvalidSourceMappings] = logLevel
210-
case "invalid-source-url":
211-
overrides[MsgID_SourceMap_InvalidSourceURL] = logLevel
212209
case "missing-source-map":
213210
overrides[MsgID_SourceMap_MissingSourceMap] = logLevel
214211
case "unsupported-source-map-comment":
@@ -341,8 +338,6 @@ func MsgIDToString(id MsgID) string {
341338
// Source maps
342339
case MsgID_SourceMap_InvalidSourceMappings:
343340
return "invalid-source-mappings"
344-
case MsgID_SourceMap_InvalidSourceURL:
345-
return "invalid-source-url"
346341
case MsgID_SourceMap_MissingSourceMap:
347342
return "missing-source-map"
348343
case MsgID_SourceMap_UnsupportedSourceMapComment:

scripts/verify-source-map.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,15 @@ const toSearchMissingSourcesIssue4104 = {
749749
'app-root': 'app.component.ts',
750750
}
751751

752+
const testCaseDefineWithObjectIssue4169 = {
753+
'entry.js': `console.log(OBJECT, ARRAY);`,
754+
}
755+
756+
const toSearchDefineWithObjectIssue4169 = {
757+
'test object': '<define:OBJECT>',
758+
'test array': '<define:ARRAY>',
759+
}
760+
752761
async function check(kind, testCase, toSearch, { outfile, flags, entryPoints, crlf, followUpFlags = [], checkFirstChunk }) {
753762
let failed = 0
754763

@@ -1243,6 +1252,12 @@ async function main() {
12431252
crlf,
12441253
followUpFlags: ['--packages=external'],
12451254
}),
1255+
check('issue-4169' + suffix, testCaseDefineWithObjectIssue4169, toSearchDefineWithObjectIssue4169, {
1256+
outfile: 'out.js',
1257+
flags: flags.concat('--format=esm', '--sourcemap', '--bundle', '--define:OBJECT={"test object":1}', '--define:ARRAY=["test array"]'),
1258+
entryPoints: ['entry.js'],
1259+
crlf,
1260+
}),
12461261

12471262
// Checks for the "names" field
12481263
checkNames('names' + suffix, testCaseNames, {

0 commit comments

Comments
 (0)