sentry-cli icon indicating copy to clipboard operation
sentry-cli copied to clipboard

Incorrect extraction of `//# sourceMappingURL=` when inside a string

Open TheYoxy opened this issue 4 weeks ago • 2 comments

CLI Version

2.58.2

Operating System and Architecture

  • [x] macOS (arm64)
  • [ ] macOS (x86_64)
  • [ ] Linux (i686)
  • [x] Linux (x86_64)
  • [ ] Linux (armv7)
  • [ ] Linux (aarch64)
  • [ ] Windows (i686)
  • [ ] Windows (x86_64)

Operating System Version

macOS Tahoe 26.1, Arch-linux

Link to reproduction repository

No response

CLI Command

sentry sourcemaps inject

Exact Reproduction Steps

Inside some bundled code I have the following code:

... some code
						code$1 += `
//# sourceMappingURL=${map.toUrl()}`;
					}
... more code

For reference, this is some code from unplugin.

Expected Results

Since the line is inside a string template, the line shouldn't be altered.

Actual Results

It removes this the sourceMappingURL line and move it to the end of the file with the generated debug id for the file. Since the end of the string is at the end of the line, it creates a syntax error since there isn't the end of the string.

For reference, when there is multiple reference of this, it only removes the last occurrence of the previous string.

Logs

There is nothing relevant in the logs.

TheYoxy avatar Dec 04 '25 11:12 TheYoxy

CLI-241

linear[bot] avatar Dec 04 '25 11:12 linear[bot]

Hi @TheYoxy, this indeed appears to be undesirable behavior.

To fully ignore //# sourceMappingURL comments which appear in template strings, we would likely need to completely rework our logic for detecting this comment by parsing the JavaScript instead of just searching the file for the string, as we currently do. The source map spec states that source mapping URLs can be extracted either via parsing or non-parsing implementations, and there is even an example in there showing how a //# sourceMappingURL appearing in a template string is a valid source mapping reference per the reference non-parsing extraction algorithm, and it appears that how to fix the problem is still an open issue.

However, for your case, since there is also some more code after the //# sourceMappingURL, it might be sufficient for us to switch over to properly using the reference non-parsing implementation, as that implementation only considers //# sourceMappingURL comments if there are no lines of code after the comment (only comments and whitespace are allowed).

szokeasaurusrex avatar Dec 10 '25 09:12 szokeasaurusrex