Skip to content

Commit

Permalink
Escape the source map URL before using it in a CSS comment
Browse files Browse the repository at this point in the history
The URL must not be allowed to terminate the comment.
  • Loading branch information
stof committed Apr 16, 2022
1 parent 3dbb552 commit e5cc828
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,9 @@
## 1.50.1

* Fix a bug where a loud comment in the source can break the source map when
embedding the sources, when using the command-line interface or the legacy JS
API.

### Embedded Sass

* The JS embedded host and the embedded compiler will now properly avoid
Expand Down
4 changes: 3 additions & 1 deletion lib/src/executable/compile_stylesheet.dart
Expand Up @@ -174,6 +174,8 @@ String _writeSourceMap(
url = p.toUri(p.relative(sourceMapPath, from: p.dirname(destination)));
}

var escapedUrl = url.toString().replaceAll("*/", "*\\/");

return (options.style == OutputStyle.compressed ? '' : '\n\n') +
'/*# sourceMappingURL=$url */';
'/*# sourceMappingURL=$escapedUrl */';
}
3 changes: 2 additions & 1 deletion lib/src/node/legacy.dart
Expand Up @@ -405,7 +405,8 @@ RenderResult _newRenderResult(
: p.toUri(outFile == null
? sourceMapPath
: p.relative(sourceMapPath, from: p.dirname(outFile)));
css += "\n\n/*# sourceMappingURL=$url */";
var escapedUrl = url.toString().replaceAll("*/", "*\\/");
css += "\n\n/*# sourceMappingURL=$escapedUrl */";
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/utils.dart
Expand Up @@ -27,7 +27,7 @@ Map<String, dynamic> embeddedSourceMap(String css) {
expect(css, matches(_sourceMapCommentRegExp));

var match = _sourceMapCommentRegExp.firstMatch(css)!;
var data = Uri.parse(match[1]!).data!;
var data = Uri.parse(match[1]!.replaceAll("*\\/", "*/")).data!;
expect(data.mimeType, equals("application/json"));
return jsonDecode(data.contentAsString()) as Map<String, dynamic>;
}
Expand Down

0 comments on commit e5cc828

Please sign in to comment.