fix(css/parser): Fix parsing of funxtion named url (#2350)

swc_css_parser:
 - Make `url` function calls to not contain space in arguments.
This commit is contained in:
Alexander Akait 2021-10-05 22:39:54 +03:00 committed by GitHub
parent fac6f47863
commit 6863d9624e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 723 additions and 67 deletions

View File

@ -6,7 +6,7 @@ edition = "2018"
license = "Apache-2.0/MIT"
name = "swc_css_parser"
repository = "https://github.com/swc-project/swc.git"
version = "0.8.2"
version = "0.8.3"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]

View File

@ -5,6 +5,7 @@ use crate::{
error::{Error, ErrorKind},
Parse,
};
use swc_atoms::js_word;
use swc_common::{BytePos, Spanned};
use swc_css_ast::*;
@ -429,9 +430,10 @@ where
let name = Text { span, value };
if eat!(self, "(") {
let is_url = name.value.to_ascii_lowercase() == js_word!("url");
let ctx = Ctx {
allow_operation_in_value: true,
allow_separating_value_with_space: true,
allow_operation_in_value: if is_url { false } else { true },
allow_separating_value_with_space: if is_url { false } else { true },
allow_separating_value_with_comma: false,
..self.ctx
};

View File

@ -4,18 +4,18 @@ a {
background-image: url('./image (1).jpg');
background-image: URL('./image (1).jpg');
background-image: url( './image (1).jpg');
/*background-image: url('./image (1).jpg' );*/
/*background-image: url( './image (1).jpg' );*/
/*background-image: url( */
/*'./image (1).jpg' */
/*);*/
/*background-image: url();*/
/*background-image: url( );*/
background-image: url('./image (1).jpg' );
background-image: url( './image (1).jpg' );
background-image: url(
'./image (1).jpg'
);
background-image: url();
background-image: url( );
background-image: url("");
/*background-image: url( "" );*/
background-image: url( "" );
background-image: url('');
/*background-image: url( '' );*/
/*background-image: url( ' ' );*/
background-image: url( '' );
background-image: url( ' ' );
background-image: url(./image.png);
background-image: url( ./image.png );
}

View File

@ -2,7 +2,7 @@
"type": "Stylesheet",
"span": {
"start": 0,
"end": 823,
"end": 783,
"ctxt": 0
},
"rules": [
@ -10,7 +10,7 @@
"type": "StyleRule",
"span": {
"start": 0,
"end": 823,
"end": 783,
"ctxt": 0
},
"selectors": [
@ -58,7 +58,7 @@
"type": "DeclBlock",
"span": {
"start": 2,
"end": 823,
"end": 783,
"ctxt": 0
},
"items": [
@ -286,15 +286,15 @@
{
"type": "Property",
"span": {
"start": 554,
"end": 579,
"start": 302,
"end": 345,
"ctxt": 0
},
"name": {
"type": "Text",
"span": {
"start": 554,
"end": 570,
"start": 302,
"end": 318,
"ctxt": 0
},
"value": "background-image"
@ -303,15 +303,15 @@
{
"type": "FnValue",
"span": {
"start": 572,
"end": 579,
"start": 320,
"end": 345,
"ctxt": 0
},
"name": {
"type": "Text",
"span": {
"start": 572,
"end": 575,
"start": 320,
"end": 323,
"ctxt": 0
},
"value": "url"
@ -320,8 +320,210 @@
{
"type": "String",
"span": {
"start": 576,
"end": 578,
"start": 324,
"end": 341,
"ctxt": 0
},
"value": "./image (1).jpg"
}
]
}
],
"important": null
},
{
"type": "Property",
"span": {
"start": 351,
"end": 397,
"ctxt": 0
},
"name": {
"type": "Text",
"span": {
"start": 351,
"end": 367,
"ctxt": 0
},
"value": "background-image"
},
"values": [
{
"type": "FnValue",
"span": {
"start": 369,
"end": 397,
"ctxt": 0
},
"name": {
"type": "Text",
"span": {
"start": 369,
"end": 372,
"ctxt": 0
},
"value": "url"
},
"args": [
{
"type": "String",
"span": {
"start": 376,
"end": 393,
"ctxt": 0
},
"value": "./image (1).jpg"
}
]
}
],
"important": null
},
{
"type": "Property",
"span": {
"start": 403,
"end": 459,
"ctxt": 0
},
"name": {
"type": "Text",
"span": {
"start": 403,
"end": 419,
"ctxt": 0
},
"value": "background-image"
},
"values": [
{
"type": "FnValue",
"span": {
"start": 421,
"end": 459,
"ctxt": 0
},
"name": {
"type": "Text",
"span": {
"start": 421,
"end": 424,
"ctxt": 0
},
"value": "url"
},
"args": [
{
"type": "String",
"span": {
"start": 433,
"end": 450,
"ctxt": 0
},
"value": "./image (1).jpg"
}
]
}
],
"important": null
},
{
"type": "Property",
"span": {
"start": 465,
"end": 488,
"ctxt": 0
},
"name": {
"type": "Text",
"span": {
"start": 465,
"end": 481,
"ctxt": 0
},
"value": "background-image"
},
"values": [
{
"type": "UrlValue",
"span": {
"start": 483,
"end": 488,
"ctxt": 0
},
"url": ""
}
],
"important": null
},
{
"type": "Property",
"span": {
"start": 494,
"end": 520,
"ctxt": 0
},
"name": {
"type": "Text",
"span": {
"start": 494,
"end": 510,
"ctxt": 0
},
"value": "background-image"
},
"values": [
{
"type": "UrlValue",
"span": {
"start": 512,
"end": 520,
"ctxt": 0
},
"url": ""
}
],
"important": null
},
{
"type": "Property",
"span": {
"start": 526,
"end": 551,
"ctxt": 0
},
"name": {
"type": "Text",
"span": {
"start": 526,
"end": 542,
"ctxt": 0
},
"value": "background-image"
},
"values": [
{
"type": "FnValue",
"span": {
"start": 544,
"end": 551,
"ctxt": 0
},
"name": {
"type": "Text",
"span": {
"start": 544,
"end": 547,
"ctxt": 0
},
"value": "url"
},
"args": [
{
"type": "String",
"span": {
"start": 548,
"end": 550,
"ctxt": 0
},
"value": ""
@ -334,15 +536,15 @@
{
"type": "Property",
"span": {
"start": 626,
"end": 651,
"start": 557,
"end": 588,
"ctxt": 0
},
"name": {
"type": "Text",
"span": {
"start": 626,
"end": 642,
"start": 557,
"end": 573,
"ctxt": 0
},
"value": "background-image"
@ -351,15 +553,15 @@
{
"type": "FnValue",
"span": {
"start": 644,
"end": 651,
"start": 575,
"end": 588,
"ctxt": 0
},
"name": {
"type": "Text",
"span": {
"start": 644,
"end": 647,
"start": 575,
"end": 578,
"ctxt": 0
},
"value": "url"
@ -368,8 +570,8 @@
{
"type": "String",
"span": {
"start": 648,
"end": 650,
"start": 582,
"end": 584,
"ctxt": 0
},
"value": ""
@ -379,11 +581,184 @@
],
"important": null
},
{
"type": "Property",
"span": {
"start": 594,
"end": 619,
"ctxt": 0
},
"name": {
"type": "Text",
"span": {
"start": 594,
"end": 610,
"ctxt": 0
},
"value": "background-image"
},
"values": [
{
"type": "FnValue",
"span": {
"start": 612,
"end": 619,
"ctxt": 0
},
"name": {
"type": "Text",
"span": {
"start": 612,
"end": 615,
"ctxt": 0
},
"value": "url"
},
"args": [
{
"type": "String",
"span": {
"start": 616,
"end": 618,
"ctxt": 0
},
"value": ""
}
]
}
],
"important": null
},
{
"type": "Property",
"span": {
"start": 625,
"end": 656,
"ctxt": 0
},
"name": {
"type": "Text",
"span": {
"start": 625,
"end": 641,
"ctxt": 0
},
"value": "background-image"
},
"values": [
{
"type": "FnValue",
"span": {
"start": 643,
"end": 656,
"ctxt": 0
},
"name": {
"type": "Text",
"span": {
"start": 643,
"end": 646,
"ctxt": 0
},
"value": "url"
},
"args": [
{
"type": "String",
"span": {
"start": 650,
"end": 652,
"ctxt": 0
},
"value": ""
}
]
}
],
"important": null
},
{
"type": "Property",
"span": {
"start": 662,
"end": 694,
"ctxt": 0
},
"name": {
"type": "Text",
"span": {
"start": 662,
"end": 678,
"ctxt": 0
},
"value": "background-image"
},
"values": [
{
"type": "FnValue",
"span": {
"start": 680,
"end": 694,
"ctxt": 0
},
"name": {
"type": "Text",
"span": {
"start": 680,
"end": 683,
"ctxt": 0
},
"value": "url"
},
"args": [
{
"type": "String",
"span": {
"start": 687,
"end": 690,
"ctxt": 0
},
"value": " "
}
]
}
],
"important": null
},
{
"type": "Property",
"span": {
"start": 700,
"end": 734,
"ctxt": 0
},
"name": {
"type": "Text",
"span": {
"start": 700,
"end": 716,
"ctxt": 0
},
"value": "background-image"
},
"values": [
{
"type": "UrlValue",
"span": {
"start": 718,
"end": 734,
"ctxt": 0
},
"url": "./image.png"
}
],
"important": null
},
{
"type": "Property",
"span": {
"start": 740,
"end": 774,
"end": 780,
"ctxt": 0
},
"name": {
@ -400,36 +775,7 @@
"type": "UrlValue",
"span": {
"start": 758,
"end": 774,
"ctxt": 0
},
"url": "./image.png"
}
],
"important": null
},
{
"type": "Property",
"span": {
"start": 780,
"end": 820,
"ctxt": 0
},
"name": {
"type": "Text",
"span": {
"start": 780,
"end": 796,
"ctxt": 0
},
"value": "background-image"
},
"values": [
{
"type": "UrlValue",
"span": {
"start": 798,
"end": 820,
"end": 780,
"ctxt": 0
},
"url": "./image.png"

View File

@ -263,6 +263,188 @@ error: Str
6 | background-image: url( './image (1).jpg');
| ^^^^^^^^^^^^^^^^^
error: Property
--> $DIR/tests/fixture/function/url/input.css:7:5
|
7 | background-image: url('./image (1).jpg' );
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: Text
--> $DIR/tests/fixture/function/url/input.css:7:5
|
7 | background-image: url('./image (1).jpg' );
| ^^^^^^^^^^^^^^^^
error: Value
--> $DIR/tests/fixture/function/url/input.css:7:23
|
7 | background-image: url('./image (1).jpg' );
| ^^^^^^^^^^^^^^^^^^^^^^^^^
error: FnValue
--> $DIR/tests/fixture/function/url/input.css:7:23
|
7 | background-image: url('./image (1).jpg' );
| ^^^^^^^^^^^^^^^^^^^^^^^^^
error: Text
--> $DIR/tests/fixture/function/url/input.css:7:23
|
7 | background-image: url('./image (1).jpg' );
| ^^^
error: Value
--> $DIR/tests/fixture/function/url/input.css:7:27
|
7 | background-image: url('./image (1).jpg' );
| ^^^^^^^^^^^^^^^^^
error: Str
--> $DIR/tests/fixture/function/url/input.css:7:27
|
7 | background-image: url('./image (1).jpg' );
| ^^^^^^^^^^^^^^^^^
error: Property
--> $DIR/tests/fixture/function/url/input.css:8:5
|
8 | background-image: url( './image (1).jpg' );
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: Text
--> $DIR/tests/fixture/function/url/input.css:8:5
|
8 | background-image: url( './image (1).jpg' );
| ^^^^^^^^^^^^^^^^
error: Value
--> $DIR/tests/fixture/function/url/input.css:8:23
|
8 | background-image: url( './image (1).jpg' );
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: FnValue
--> $DIR/tests/fixture/function/url/input.css:8:23
|
8 | background-image: url( './image (1).jpg' );
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: Text
--> $DIR/tests/fixture/function/url/input.css:8:23
|
8 | background-image: url( './image (1).jpg' );
| ^^^
error: Value
--> $DIR/tests/fixture/function/url/input.css:8:30
|
8 | background-image: url( './image (1).jpg' );
| ^^^^^^^^^^^^^^^^^
error: Str
--> $DIR/tests/fixture/function/url/input.css:8:30
|
8 | background-image: url( './image (1).jpg' );
| ^^^^^^^^^^^^^^^^^
error: Property
--> $DIR/tests/fixture/function/url/input.css:9:5
|
9 | / background-image: url(
10 | | './image (1).jpg'
11 | | );
| |_____^
error: Text
--> $DIR/tests/fixture/function/url/input.css:9:5
|
9 | background-image: url(
| ^^^^^^^^^^^^^^^^
error: Value
--> $DIR/tests/fixture/function/url/input.css:9:23
|
9 | background-image: url(
| _______________________^
10 | | './image (1).jpg'
11 | | );
| |_____^
error: FnValue
--> $DIR/tests/fixture/function/url/input.css:9:23
|
9 | background-image: url(
| _______________________^
10 | | './image (1).jpg'
11 | | );
| |_____^
error: Text
--> $DIR/tests/fixture/function/url/input.css:9:23
|
9 | background-image: url(
| ^^^
error: Value
--> $DIR/tests/fixture/function/url/input.css:10:5
|
10 | './image (1).jpg'
| ^^^^^^^^^^^^^^^^^
error: Str
--> $DIR/tests/fixture/function/url/input.css:10:5
|
10 | './image (1).jpg'
| ^^^^^^^^^^^^^^^^^
error: Property
--> $DIR/tests/fixture/function/url/input.css:12:5
|
12 | background-image: url();
| ^^^^^^^^^^^^^^^^^^^^^^^
error: Text
--> $DIR/tests/fixture/function/url/input.css:12:5
|
12 | background-image: url();
| ^^^^^^^^^^^^^^^^
error: Value
--> $DIR/tests/fixture/function/url/input.css:12:23
|
12 | background-image: url();
| ^^^^^
error: UrlValue
--> $DIR/tests/fixture/function/url/input.css:12:23
|
12 | background-image: url();
| ^^^^^
error: Property
--> $DIR/tests/fixture/function/url/input.css:13:5
|
13 | background-image: url( );
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
error: Text
--> $DIR/tests/fixture/function/url/input.css:13:5
|
13 | background-image: url( );
| ^^^^^^^^^^^^^^^^
error: Value
--> $DIR/tests/fixture/function/url/input.css:13:23
|
13 | background-image: url( );
| ^^^^^^^^
error: UrlValue
--> $DIR/tests/fixture/function/url/input.css:13:23
|
13 | background-image: url( );
| ^^^^^^^^
error: Property
--> $DIR/tests/fixture/function/url/input.css:14:5
|
@ -305,6 +487,48 @@ error: Str
14 | background-image: url("");
| ^^
error: Property
--> $DIR/tests/fixture/function/url/input.css:15:5
|
15 | background-image: url( "" );
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: Text
--> $DIR/tests/fixture/function/url/input.css:15:5
|
15 | background-image: url( "" );
| ^^^^^^^^^^^^^^^^
error: Value
--> $DIR/tests/fixture/function/url/input.css:15:23
|
15 | background-image: url( "" );
| ^^^^^^^^^^^^^
error: FnValue
--> $DIR/tests/fixture/function/url/input.css:15:23
|
15 | background-image: url( "" );
| ^^^^^^^^^^^^^
error: Text
--> $DIR/tests/fixture/function/url/input.css:15:23
|
15 | background-image: url( "" );
| ^^^
error: Value
--> $DIR/tests/fixture/function/url/input.css:15:30
|
15 | background-image: url( "" );
| ^^
error: Str
--> $DIR/tests/fixture/function/url/input.css:15:30
|
15 | background-image: url( "" );
| ^^
error: Property
--> $DIR/tests/fixture/function/url/input.css:16:5
|
@ -347,6 +571,90 @@ error: Str
16 | background-image: url('');
| ^^
error: Property
--> $DIR/tests/fixture/function/url/input.css:17:5
|
17 | background-image: url( '' );
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: Text
--> $DIR/tests/fixture/function/url/input.css:17:5
|
17 | background-image: url( '' );
| ^^^^^^^^^^^^^^^^
error: Value
--> $DIR/tests/fixture/function/url/input.css:17:23
|
17 | background-image: url( '' );
| ^^^^^^^^^^^^^
error: FnValue
--> $DIR/tests/fixture/function/url/input.css:17:23
|
17 | background-image: url( '' );
| ^^^^^^^^^^^^^
error: Text
--> $DIR/tests/fixture/function/url/input.css:17:23
|
17 | background-image: url( '' );
| ^^^
error: Value
--> $DIR/tests/fixture/function/url/input.css:17:30
|
17 | background-image: url( '' );
| ^^
error: Str
--> $DIR/tests/fixture/function/url/input.css:17:30
|
17 | background-image: url( '' );
| ^^
error: Property
--> $DIR/tests/fixture/function/url/input.css:18:5
|
18 | background-image: url( ' ' );
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: Text
--> $DIR/tests/fixture/function/url/input.css:18:5
|
18 | background-image: url( ' ' );
| ^^^^^^^^^^^^^^^^
error: Value
--> $DIR/tests/fixture/function/url/input.css:18:23
|
18 | background-image: url( ' ' );
| ^^^^^^^^^^^^^^
error: FnValue
--> $DIR/tests/fixture/function/url/input.css:18:23
|
18 | background-image: url( ' ' );
| ^^^^^^^^^^^^^^
error: Text
--> $DIR/tests/fixture/function/url/input.css:18:23
|
18 | background-image: url( ' ' );
| ^^^
error: Value
--> $DIR/tests/fixture/function/url/input.css:18:30
|
18 | background-image: url( ' ' );
| ^^^
error: Str
--> $DIR/tests/fixture/function/url/input.css:18:30
|
18 | background-image: url( ' ' );
| ^^^
error: Property
--> $DIR/tests/fixture/function/url/input.css:19:5
|