From da7685e5351db0e4fa05d2687b982e40d1d08aac Mon Sep 17 00:00:00 2001 From: bobihuang Date: Mon, 23 Dec 2024 23:56:45 +0800 Subject: [PATCH] fix: parsing process for handling strings with multiple spaces --- 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 cdca4895fcb3..00cbcd3be060 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 000000000000..c58d966b87a0 --- /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 000000000000..4fe51c72d641 --- /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 000000000000..328d5ecda4ef --- /dev/null +++ b/packages/rspack-test-tools/tests/builtinCases/plugin-css/simple-url/style.css @@ -0,0 +1,3 @@ +body { + background: red url(' '); +}