Skip to content

Commit

Permalink
CSS: keep source mapping URLs, fixes #692
Browse files Browse the repository at this point in the history
  • Loading branch information
tdewolff committed May 2, 2024
1 parent a58eb58 commit dc25ed9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
4 changes: 3 additions & 1 deletion css/css.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,13 @@ func (c *cssMinifier) minifyGrammar() {
c.w.Write(value)
semicolonQueued = true
case css.CommentGrammar:
if len(data) > 5 && data[1] == '*' && data[2] == '!' {
if 5 < len(data) && data[1] == '*' && data[2] == '!' {
c.w.Write(data[:3])
comment := parse.TrimWhitespace(parse.ReplaceMultipleWhitespace(data[3 : len(data)-2]))
c.w.Write(comment)
c.w.Write(data[len(data)-2:])
} else if 5 < len(data) && (data[2] == '#' || data[2] == '@') {
c.w.Write(data) // sourceMappingURL
}
default:
c.w.Write(data)
Expand Down
1 change: 1 addition & 0 deletions css/css_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func TestCSS(t *testing.T) {
}{
{"/*comment*/", ""},
{"/*! bang comment */", "/*!bang comment*/"},
{"/*# sourceMappingURL=url */", "/*# sourceMappingURL=url */"},
{"a;", "a"},
{"i{}/*! bang comment */", "i{}/*!bang comment*/"},
{"i { key: value; key2: value; }", "i{key:value;key2:value}"},
Expand Down

0 comments on commit dc25ed9

Please sign in to comment.