Parser: fix ambiguity with whitespace in version ranges (#40344)
Allowing white space around `:` in version ranges introduces an ambiguity: ``` a@1: b ``` parses as `a@1:b` but should really be parsed as two separate specs `a@1:` and `b`. With white space disallowed around `:` in ranges, the ambiguity is resolved.
This commit is contained in:
parent
e5f3ffc04f
commit
ac976a4bf4
2 changed files with 29 additions and 16 deletions
|
@ -96,9 +96,9 @@
|
|||
VALUE = r"(?:[a-zA-Z_0-9\-+\*.,:=\~\/\\]+)"
|
||||
QUOTED_VALUE = r"[\"']+(?:[a-zA-Z_0-9\-+\*.,:=\~\/\\\s]+)[\"']+"
|
||||
|
||||
VERSION = r"=?([a-zA-Z0-9_][a-zA-Z_0-9\-\.]*\b)"
|
||||
VERSION_RANGE = rf"({VERSION}\s*:\s*{VERSION}(?!\s*=)|:\s*{VERSION}(?!\s*=)|{VERSION}\s*:|:)"
|
||||
VERSION_LIST = rf"({VERSION_RANGE}|{VERSION})(\s*[,]\s*({VERSION_RANGE}|{VERSION}))*"
|
||||
VERSION = r"=?(?:[a-zA-Z0-9_][a-zA-Z_0-9\-\.]*\b)"
|
||||
VERSION_RANGE = rf"(?:(?:{VERSION})?:(?:{VERSION}(?!\s*=))?)"
|
||||
VERSION_LIST = rf"(?:{VERSION_RANGE}|{VERSION})(?:\s*,\s*(?:{VERSION_RANGE}|{VERSION}))*"
|
||||
|
||||
|
||||
class TokenBase(enum.Enum):
|
||||
|
|
|
@ -472,13 +472,26 @@ def _specfile_for(spec_str, filename):
|
|||
[Token(TokenType.PROPAGATED_KEY_VALUE_PAIR, value='cflags=="-O3 -g"')],
|
||||
'cflags=="-O3 -g"',
|
||||
),
|
||||
# Way too many spaces
|
||||
# Whitespace is allowed in version lists
|
||||
("@1.2:1.4 , 1.6 ", [Token(TokenType.VERSION, value="@1.2:1.4 , 1.6")], "@1.2:1.4,1.6"),
|
||||
# But not in ranges. `a@1:` and `b` are separate specs, not a single `a@1:b`.
|
||||
(
|
||||
"@1.2 : 1.4 , 1.6 ",
|
||||
[Token(TokenType.VERSION, value="@1.2 : 1.4 , 1.6")],
|
||||
"@1.2:1.4,1.6",
|
||||
"a@1: b",
|
||||
[
|
||||
Token(TokenType.UNQUALIFIED_PACKAGE_NAME, value="a"),
|
||||
Token(TokenType.VERSION, value="@1:"),
|
||||
Token(TokenType.UNQUALIFIED_PACKAGE_NAME, value="b"),
|
||||
],
|
||||
"a@1:",
|
||||
),
|
||||
(
|
||||
"@1.2: develop = foo",
|
||||
[
|
||||
Token(TokenType.VERSION, value="@1.2:"),
|
||||
Token(TokenType.KEY_VALUE_PAIR, value="develop = foo"),
|
||||
],
|
||||
"@1.2: develop=foo",
|
||||
),
|
||||
("@1.2 : develop", [Token(TokenType.VERSION, value="@1.2 : develop")], "@1.2:develop"),
|
||||
(
|
||||
"@1.2:develop = foo",
|
||||
[
|
||||
|
|
Loading…
Reference in a new issue