From 6a4c425345152205d5043a1898d6818ee18857f8 Mon Sep 17 00:00:00 2001 From: Jakub Pawlowicz Date: Wed, 21 Dec 2016 12:05:46 +0100 Subject: [PATCH] Fixed #432 - adds URLs normalization. Why: * So further merging or compacting can happen more effectively even when initial URL formatting is different. --- History.md | 1 + lib/reader/rewrite-url.js | 3 +- test/fixtures/issue-432-min.css | 1 + test/fixtures/issue-432.css | 77 +++++++++++++++++++++++++++++++++ 4 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/issue-432-min.css create mode 100644 test/fixtures/issue-432.css diff --git a/History.md b/History.md index 45769eb2..2af7aed6 100644 --- a/History.md +++ b/History.md @@ -7,6 +7,7 @@ * Replaces the old tokenizer with a new one which doesn't use any escaping. * Replaces the old `@import` inlining with one on top of the new tokenizer. * Simplifies URL rebasing with a single `rebaseTo` option in API or inferred from `--output` in CLI. +* Fixed issue [#432](https://github.com/jakubpawlowicz/clean-css/issues/432) - adds URLs normalization. * Fixed issue [#657](https://github.com/jakubpawlowicz/clean-css/issues/657) - adds property name validation. * Fixed issue [#686](https://github.com/jakubpawlowicz/clean-css/issues/686) - adds rounding precision for all units. * Fixed issue [#756](https://github.com/jakubpawlowicz/clean-css/issues/756) - adds disabling font-weight optimizations. diff --git a/lib/reader/rewrite-url.js b/lib/reader/rewrite-url.js index 4fefbafb..29b09f79 100644 --- a/lib/reader/rewrite-url.js +++ b/lib/reader/rewrite-url.js @@ -103,7 +103,8 @@ function rewriteUrl(originalUrl, rebaseConfig, pathOnly) { var unquotedUrl = strippedUrl .replace(QUOTE_PREFIX_PATTERN, '') - .replace(QUOTE_SUFFIX_PATTERN, ''); + .replace(QUOTE_SUFFIX_PATTERN, '') + .trim(); var quote = strippedUrl[0] == SINGLE_QUOTE || strippedUrl[0] == DOUBLE_QUOTE ? strippedUrl[0] : diff --git a/test/fixtures/issue-432-min.css b/test/fixtures/issue-432-min.css new file mode 100644 index 00000000..8f249648 --- /dev/null +++ b/test/fixtures/issue-432-min.css @@ -0,0 +1 @@ +.c,.c-10,.c-11,.c-12,.c-2,.c-3,.c-4,.c-5,.c-6,.c-7,.c-8,.c-9{background-image:url(test/fixtures/images/image.png)} diff --git a/test/fixtures/issue-432.css b/test/fixtures/issue-432.css new file mode 100644 index 00000000..316a9a8b --- /dev/null +++ b/test/fixtures/issue-432.css @@ -0,0 +1,77 @@ +/* Assets with non-stylistic syntax */ + +.c { + + background-image:url('images/image.png'); + +} + +.c-2 { + + background-image: url('images/image.png'); + +} + +.c-3 { + + background-image: + url('images/image.png'); + +} + +.c-4 { + + background-image: url( 'images/image.png'); + +} + +.c-5 { + + background-image: url( +'images/image.png'); + +} + +.c-6 { + + background-image: url(' images/image.png'); + +} + +.c-7 { + + background-image: url('images/image.png '); + +} + +.c-8 { + + background-image: url('images/image.png' ); + +} + +.c-9 { + + background-image: url('images/image.png' +); + +} + +.c-10 { + + background-image: url('images/image.png') ; + +} + +.c-11 { + + background-image: url('images/image.png') +; + +} + +.c-12 { + + background-image: URL('images/image.png'); + +} -- 2.34.1