@@ -268,4 +268,219 @@ background-color: green;`)
268268 ` ) ;
269269 } ) ;
270270 } ) ;
271+
272+ describe ( 'url() function handling' , ( ) => {
273+ it ( 'preserves unquoted https:// URL in url()' , ( ) => {
274+ expect (
275+ stylisTest ( `
276+ background-image: url(https://example.com/image.png);
277+ background-color: green;
278+ ` )
279+ ) . toMatchInlineSnapshot ( `
280+ [
281+ ".a{background-image:url(https://example.com/image.png);background-color:green;}",
282+ ]
283+ ` ) ;
284+ } ) ;
285+
286+ it ( 'preserves unquoted http:// URL in url()' , ( ) => {
287+ expect (
288+ stylisTest ( `
289+ background-image: url(http://example.com/image.png);
290+ background-color: green;
291+ ` )
292+ ) . toMatchInlineSnapshot ( `
293+ [
294+ ".a{background-image:url(http://example.com/image.png);background-color:green;}",
295+ ]
296+ ` ) ;
297+ } ) ;
298+
299+ it ( 'preserves double-quoted URL in url()' , ( ) => {
300+ expect (
301+ stylisTest ( `
302+ background-image: url("https://example.com/image.png");
303+ background-color: green;
304+ ` )
305+ ) . toMatchInlineSnapshot ( `
306+ [
307+ ".a{background-image:url("https://example.com/image.png");background-color:green;}",
308+ ]
309+ ` ) ;
310+ } ) ;
311+
312+ it ( 'preserves single-quoted URL in url()' , ( ) => {
313+ expect (
314+ stylisTest ( `
315+ background-image: url('https://example.com/image.png');
316+ background-color: green;
317+ ` )
318+ ) . toMatchInlineSnapshot ( `
319+ [
320+ ".a{background-image:url('https://example.com/image.png');background-color:green;}",
321+ ]
322+ ` ) ;
323+ } ) ;
324+
325+ it ( 'preserves data URL in url()' , ( ) => {
326+ expect (
327+ stylisTest ( `
328+ background-image: url(data:image/png;base64,iVBORw0KGgo=);
329+ background-color: green;
330+ ` )
331+ ) . toMatchInlineSnapshot ( `
332+ [
333+ ".a{background-image:url(data:image/png;base64,iVBORw0KGgo=);background-color:green;}",
334+ ]
335+ ` ) ;
336+ } ) ;
337+
338+ it ( 'preserves URL with path and query params' , ( ) => {
339+ expect (
340+ stylisTest ( `
341+ background-image: url(https://example.com/path/to/image.png?v=1&size=large);
342+ background-color: green;
343+ ` )
344+ ) . toMatchInlineSnapshot ( `
345+ [
346+ ".a{background-image:url(https://example.com/path/to/image.png?v=1&size=large);background-color:green;}",
347+ ]
348+ ` ) ;
349+ } ) ;
350+
351+ it ( 'preserves multiple url() declarations' , ( ) => {
352+ expect (
353+ stylisTest ( `
354+ background-image: url(https://example.com/bg.png);
355+ cursor: url(https://example.com/cursor.png), auto;
356+ list-style-image: url(https://example.com/bullet.png);
357+ ` )
358+ ) . toMatchInlineSnapshot ( `
359+ [
360+ ".a{background-image:url(https://example.com/bg.png);cursor:url(https://example.com/cursor.png),auto;list-style-image:url(https://example.com/bullet.png);}",
361+ ]
362+ ` ) ;
363+ } ) ;
364+
365+ it ( 'preserves @font-face with unquoted URL' , ( ) => {
366+ expect (
367+ stylisTest ( `
368+ @font-face {
369+ font-family: 'MyFont';
370+ src: url(https://example.com/fonts/myfont.woff2) format('woff2');
371+ }
372+ ` )
373+ ) . toMatchInlineSnapshot ( `
374+ [
375+ "@font-face{font-family:'MyFont';src:url(https://example.com/fonts/myfont.woff2) format('woff2');}",
376+ ]
377+ ` ) ;
378+ } ) ;
379+
380+ it ( 'preserves @font-face with multiple src URLs' , ( ) => {
381+ expect (
382+ stylisTest ( `
383+ @font-face {
384+ font-family: 'MyFont';
385+ src: url(https://example.com/fonts/myfont.woff2) format('woff2'),
386+ url(https://example.com/fonts/myfont.woff) format('woff');
387+ }
388+ ` )
389+ ) . toMatchInlineSnapshot ( `
390+ [
391+ "@font-face{font-family:'MyFont';src:url(https://example.com/fonts/myfont.woff2) format('woff2'),url(https://example.com/fonts/myfont.woff) format('woff');}",
392+ ]
393+ ` ) ;
394+ } ) ;
395+
396+ it ( 'preserves @import with URL' , ( ) => {
397+ expect (
398+ stylisTest ( `
399+ @import url(https://example.com/styles.css);
400+ background-color: green;
401+ ` )
402+ ) . toMatchInlineSnapshot ( `
403+ [
404+ ".a{background-color:green;}",
405+ "@import url(https://example.com/styles.css);",
406+ ]
407+ ` ) ;
408+ } ) ;
409+
410+ it ( 'preserves url() with file:// protocol' , ( ) => {
411+ expect (
412+ stylisTest ( `
413+ background-image: url(file:///path/to/image.png);
414+ background-color: green;
415+ ` )
416+ ) . toMatchInlineSnapshot ( `
417+ [
418+ ".a{background-image:url(file:///path/to/image.png);background-color:green;}",
419+ ]
420+ ` ) ;
421+ } ) ;
422+
423+ it ( 'preserves url() with protocol-relative URL' , ( ) => {
424+ expect (
425+ stylisTest ( `
426+ background-image: url(//example.com/image.png);
427+ background-color: green;
428+ ` )
429+ ) . toMatchInlineSnapshot ( `
430+ [
431+ ".a{background-image:url(//example.com/image.png);background-color:green;}",
432+ ]
433+ ` ) ;
434+ } ) ;
435+
436+ it ( 'handles mix of url() and line comments' , ( ) => {
437+ expect (
438+ stylisTest ( `
439+ background-image: url(https://example.com/image.png); // this is a comment
440+ background-color: green;
441+ ` )
442+ ) . toMatchInlineSnapshot ( `
443+ [
444+ ".a{background-image:url(https://example.com/image.png);background-color:green;}",
445+ ]
446+ ` ) ;
447+ } ) ;
448+
449+ it ( 'preserves srcset URLs in image-set()' , ( ) => {
450+ expect (
451+ stylisTest ( `
452+ background-image: image-set(url(https://example.com/image.png) 1x, url(https://example.com/[email protected] ) 2x); 453+ background-color: green;
454+ ` )
455+ ) . toMatchInlineSnapshot ( `
456+ [
457+ ".a{background-image:image-set(url(https://example.com/image.png) 1x, url(https://example.com/[email protected] ) 2x);background-color:green;}", 458+ ]
459+ ` ) ;
460+ } ) ;
461+
462+ it ( 'does not match url inside other words (word boundary check)' , ( ) => {
463+ // 'foourl(' should not be treated as url()
464+ expect (
465+ stylisTest ( `
466+ width: 100px; // comment
467+ content: "foourl(https://example.com)";
468+ background-color: green;
469+ ` )
470+ ) . toMatchInlineSnapshot ( `
471+ [
472+ ".a{width:100px;content:"foourl(https://example.com)";background-color:green;}",
473+ ]
474+ ` ) ;
475+ } ) ;
476+
477+ it ( 'preserves url() at the start of CSS' , ( ) => {
478+ expect ( stylisTest ( `background-image: url(https://example.com/image.png);` ) )
479+ . toMatchInlineSnapshot ( `
480+ [
481+ ".a{background-image:url(https://example.com/image.png);}",
482+ ]
483+ ` ) ;
484+ } ) ;
485+ } ) ;
271486} ) ;
0 commit comments