From 698f036f86c4917b0dfe43e8fd22034185a31cb3 Mon Sep 17 00:00:00 2001 From: Brijesh Bittu Date: Tue, 28 May 2024 12:30:39 +0530 Subject: [PATCH] [fix] Ignore urls starting with # (#106) --- packages/pigment-css-unplugin/src/utils.ts | 3 ++- packages/pigment-css-unplugin/tests/utils.test.ts | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/pigment-css-unplugin/src/utils.ts b/packages/pigment-css-unplugin/src/utils.ts index da108320..7ea63a6d 100644 --- a/packages/pigment-css-unplugin/src/utils.ts +++ b/packages/pigment-css-unplugin/src/utils.ts @@ -29,7 +29,8 @@ export const handleUrlReplacement = async ( if ( mainItem.startsWith('data:') || mainItem.startsWith('http:') || - mainItem.startsWith('https:') + mainItem.startsWith('https:') || + mainItem.startsWith('#') ) { newCss += `url(${mainItem})`; } else if (mainItem[0] === '/') { diff --git a/packages/pigment-css-unplugin/tests/utils.test.ts b/packages/pigment-css-unplugin/tests/utils.test.ts index c0f8a4bd..c3310fbb 100644 --- a/packages/pigment-css-unplugin/tests/utils.test.ts +++ b/packages/pigment-css-unplugin/tests/utils.test.ts @@ -11,8 +11,8 @@ const dummyResolver = (url: string) => { describe('utils', () => { describe('handleUrlReplacement', () => { - it('should not replace http/data/absolute urls', async () => { - [DATA_URI, HTML_LOGO_URL, ABSOLUTE_PATH].forEach(async (url) => { + it('should not replace http/data/absolute/hash urls', async () => { + [DATA_URI, HTML_LOGO_URL, ABSOLUTE_PATH, '#my_gradient'].forEach(async (url) => { const cssString1 = `.className { background-image: url(${url}); }`;