From 7607a4e1939ac6d87aba77f1eea78c016e657e81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B3=A2=E6=AF=94=E5=B0=8F=E9=87=91=E5=88=9A?= <2890636389@qq.com> Date: Tue, 24 Dec 2024 14:12:49 +0800 Subject: [PATCH] fix: Rspack cssParser will parse failed when url(' ') (#8824) fix: parsing process for handling strings with multiple spaces Co-authored-by: bobihuang --- crates/rspack_plugin_css/src/parser_and_generator/mod.rs | 2 +- .../plugin-css/simple-url/__snapshots__/output.snap.txt | 7 +++++++ .../tests/builtinCases/plugin-css/simple-url/index.js | 1 + .../tests/builtinCases/plugin-css/simple-url/style.css | 3 +++ 4 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 packages/rspack-test-tools/tests/builtinCases/plugin-css/simple-url/__snapshots__/output.snap.txt create mode 100644 packages/rspack-test-tools/tests/builtinCases/plugin-css/simple-url/index.js create mode 100644 packages/rspack-test-tools/tests/builtinCases/plugin-css/simple-url/style.css diff --git a/crates/rspack_plugin_css/src/parser_and_generator/mod.rs b/crates/rspack_plugin_css/src/parser_and_generator/mod.rs index cdca4895fcb..00cbcd3be06 100644 --- a/crates/rspack_plugin_css/src/parser_and_generator/mod.rs +++ b/crates/rspack_plugin_css/src/parser_and_generator/mod.rs @@ -164,7 +164,7 @@ impl ParserAndGenerator for CssParserAndGenerator { range, kind, } => { - if request.is_empty() { + if request.trim().is_empty() { continue; } let request = replace_module_request_prefix( diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-css/simple-url/__snapshots__/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-css/simple-url/__snapshots__/output.snap.txt new file mode 100644 index 00000000000..c58d966b87a --- /dev/null +++ b/packages/rspack-test-tools/tests/builtinCases/plugin-css/simple-url/__snapshots__/output.snap.txt @@ -0,0 +1,7 @@ +```css title=main.css +body { + background: red url(' '); +} + + +``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-css/simple-url/index.js b/packages/rspack-test-tools/tests/builtinCases/plugin-css/simple-url/index.js new file mode 100644 index 00000000000..4fe51c72d64 --- /dev/null +++ b/packages/rspack-test-tools/tests/builtinCases/plugin-css/simple-url/index.js @@ -0,0 +1 @@ +import "./style.css"; diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-css/simple-url/style.css b/packages/rspack-test-tools/tests/builtinCases/plugin-css/simple-url/style.css new file mode 100644 index 00000000000..328d5ecda4e --- /dev/null +++ b/packages/rspack-test-tools/tests/builtinCases/plugin-css/simple-url/style.css @@ -0,0 +1,3 @@ +body { + background: red url(' '); +}