Skip to content

Commit

Permalink
CSS: fix @import url( )
Browse files Browse the repository at this point in the history
  • Loading branch information
tdewolff committed Jul 27, 2021
1 parent a8b6737 commit f571872
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
8 changes: 6 additions & 2 deletions css/css.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,14 @@ func (c *cssMinifier) minifyGrammar() {
a++
}
b := len(url) - 2
for parse.IsWhitespace(url[b]) || parse.IsNewline(url[b]) {
for a < b && (parse.IsWhitespace(url[b]) || parse.IsNewline(url[b])) {
b--
}
url = url[a-1 : b+2]
if a == b {
url = url[:2]
} else {
url = url[a-1 : b+2]
}
url[0] = '"'
url[len(url)-1] = '"'
} else {
Expand Down
5 changes: 3 additions & 2 deletions css/css_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ func TestCSS(t *testing.T) {
{"{d:url( \n \n\t0", "{d:url()}"},
{"{d:urL( '0", `{d:url("'")}`},
{`{-ms-filter:"`, `{-ms-filter:"}`},
{"@import url(", "@import url("},
{"@import url( ", "@import url( "},
{"@import url(", `@import url(`},
{"@import url( ", `@import url( `},
{"@import url( )", `@import ""`},
}

m := minify.New()
Expand Down

0 comments on commit f571872

Please sign in to comment.