@@ -46,18 +46,18 @@ def explode_factor(group: list[tuple[str, bool]]) -> str:
46
46
return "-" .join ([name for name , _ in group ])
47
47
48
48
49
- def expand_factors (value : str ) -> Iterator [tuple [Iterator [list [tuple [str , bool ]]] | None , str ]]:
49
+ def expand_factors (value : str ) -> Iterator [tuple [list [list [tuple [str , bool ]]] | None , str ]]:
50
50
for line in value .split ("\n " ):
51
- match = re . match ( r"^((?P<factor_expr>[\w{}.!,-]+):\s+)?(?P<content>.*?)$" , line )
52
- if match is None : # pragma: no cover
53
- raise RuntimeError ( "for a valid factor regex this cannot happen" )
54
- groups = match . groupdict ()
55
- factor_expr , content = groups [ "factor_expr" ], groups [ "content" ]
56
- if factor_expr is not None :
57
- factors = find_factor_groups ( factor_expr )
58
- yield factors , content
59
- else :
60
- yield None , content
51
+ factors : list [ list [ tuple [ str , bool ]]] | None = None
52
+ marker_at , content = line . find ( ":" ), line
53
+ if marker_at != - 1 :
54
+ try :
55
+ factors = list ( find_factor_groups ( line [: marker_at ]. strip ()))
56
+ except ValueError :
57
+ pass # when cannot extract factors keep the entire line
58
+ else :
59
+ content = line [ marker_at + 1 :]. strip ()
60
+ yield factors , content
61
61
62
62
63
63
def find_factor_groups (value : str ) -> Iterator [list [tuple [str , bool ]]]:
@@ -76,6 +76,8 @@ def expand_env_with_negation(value: str) -> Iterator[str]:
76
76
parts = [re .sub (r"\s+" , "" , elem ).split ("," ) for elem in elements ]
77
77
for variant in product (* parts ):
78
78
variant_str = "" .join (variant )
79
+ if not re .fullmatch (r"!?[\w._][\w._-]*" , variant_str ):
80
+ raise ValueError (variant_str )
79
81
yield variant_str
80
82
81
83
0 commit comments