Skip to content

Commit 1e211d6

Browse files
authored
Escape the source map URL before using it in a CSS comment (#1676)
The URL must not be allowed to terminate the comment.
1 parent 7004d49 commit 1e211d6

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
* Fix an issue where source locations tracked through variable references could
44
potentially become incorrect.
5+
* Fix a bug where a loud comment in the source can break the source map when
6+
embedding the sources, when using the command-line interface or the legacy JS
7+
API.
58

69
## 1.51.0
710

lib/src/executable/compile_stylesheet.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@ String _writeSourceMap(
174174
url = p.toUri(p.relative(sourceMapPath, from: p.dirname(destination)));
175175
}
176176

177+
var escapedUrl = url.toString().replaceAll("*/", '%2A/');
178+
177179
return (options.style == OutputStyle.compressed ? '' : '\n\n') +
178-
'/*# sourceMappingURL=$url */';
180+
'/*# sourceMappingURL=$escapedUrl */';
179181
}

lib/src/node/legacy.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,8 @@ RenderResult _newRenderResult(
405405
: p.toUri(outFile == null
406406
? sourceMapPath
407407
: p.relative(sourceMapPath, from: p.dirname(outFile)));
408-
css += "\n\n/*# sourceMappingURL=$url */";
408+
var escapedUrl = url.toString().replaceAll("*/", '%2A/');
409+
css += "\n\n/*# sourceMappingURL=$escapedUrl */";
409410
}
410411
}
411412

0 commit comments

Comments
 (0)