From 00c8d32b124454d28b193c878d31d98b03ded438 Mon Sep 17 00:00:00 2001 From: Rui Marinho Date: Thu, 17 Oct 2019 01:43:18 +0100 Subject: [PATCH] Skip empty src URLs in CSS declarations --- lib/utils/css-url.js | 4 ++++ test/plugins/postcss-flatten-url.js | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/lib/utils/css-url.js b/lib/utils/css-url.js index c13408b..a45f668 100644 --- a/lib/utils/css-url.js +++ b/lib/utils/css-url.js @@ -3,6 +3,10 @@ const dataURI = require('../utils/data-uri'); module.exports = (node, skipCheck) => { if (node.type === 'function' && node.value === 'url') { + if (node.nodes.length === 0) { + return; + } + node = node.nodes[0]; skipCheck = true; } diff --git a/test/plugins/postcss-flatten-url.js b/test/plugins/postcss-flatten-url.js index 63a9159..09af2c8 100644 --- a/test/plugins/postcss-flatten-url.js +++ b/test/plugins/postcss-flatten-url.js @@ -21,6 +21,13 @@ describe('postcss-flatten-url', () => { ); }); + it('should ignore empty src URLs', () => { + return test( + '@font-face { font-family: Noto Sans; src: url() format("opentype"); }', + '@font-face { font-family: Noto Sans; src: url() format("opentype"); }' + ); + }); + it('should replace the URL in a property', () => { return test( '.flatten { background: url("example.png") }',