Skip to content

Commit

Permalink
fix(css): vitejs#3729 filter out function name suffixes with url
Browse files Browse the repository at this point in the history
  • Loading branch information
Sociosarbis committed Jun 10, 2021
1 parent 0b6c7f2 commit 3efbcb0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
27 changes: 27 additions & 0 deletions packages/vite/src/node/__tests__/plugins/css.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { cssUrlRE } from '../../plugins/css'

describe('search css url function', () => {
test('some spaces before it', () => {
expect(
cssUrlRE.test("list-style-image: url('../images/bullet.jpg');")
).toBe(true)
})

test('no space after colon', () => {
expect(cssUrlRE.test("list-style-image:url('../images/bullet.jpg');")).toBe(
true
)
})

test('at the beginning of line', () => {
expect(cssUrlRE.test("url('../images/bullet.jpg');")).toBe(true)
})

test('as suffix of a function name', () => {
expect(
cssUrlRE.test(`@function svg-url($string) {
@return "";
}`)
).toBe(false)
})
})
2 changes: 1 addition & 1 deletion packages/vite/src/node/plugins/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ type CssUrlReplacer = (
url: string,
importer?: string
) => string | Promise<string>
const cssUrlRE = /url\(\s*('[^']+'|"[^"]+"|[^'")]+)\s*\)/
export const cssUrlRE = /(?:^|\:|\s)url\(\s*('[^']+'|"[^"]+"|[^'")]+)\s*\)/
const cssImageSetRE = /image-set\(([^)]+)\)/

const UrlRewritePostcssPlugin: Postcss.PluginCreator<{
Expand Down

0 comments on commit 3efbcb0

Please sign in to comment.