Require a colon in //@ normalize-*: headers

This commit is contained in:
Zalathar 2024-06-21 15:15:58 +10:00
parent 9aaa0c5867
commit b6773591ee
2 changed files with 7 additions and 17 deletions

View File

@ -1121,13 +1121,11 @@ fn expand_variables(mut value: String, config: &Config) -> String {
/// normalize-*: "REGEX" -> "REPLACEMENT"
/// ```
fn parse_normalize_rule(header: &str) -> Option<(String, String)> {
// FIXME(#126370): A colon after the header name should be mandatory, but
// currently is not, and there are many tests that lack the colon.
// FIXME: Support escaped double-quotes in strings.
let captures = static_regex!(
r#"(?x) # (verbose mode regex)
^
[^:\s]+:?\s* # (header name followed by optional colon)
[^:\s]+:\s* # (header name followed by colon)
"(?<regex>[^"]*)" # "REGEX"
\s+->\s+ # ->
"(?<replacement>[^"]*)" # "REPLACEMENT"

View File

@ -33,20 +33,11 @@ fn make_test_description<R: Read>(
#[test]
fn test_parse_normalize_rule() {
let good_data = &[
(
r#"normalize-stderr-32bit: "something (32 bits)" -> "something ($WORD bits)""#,
"something (32 bits)",
"something ($WORD bits)",
),
// FIXME(#126370): A colon after the header name should be mandatory,
// but currently is not, and there are many tests that lack the colon.
(
r#"normalize-stderr-32bit "something (32 bits)" -> "something ($WORD bits)""#,
"something (32 bits)",
"something ($WORD bits)",
),
];
let good_data = &[(
r#"normalize-stderr-32bit: "something (32 bits)" -> "something ($WORD bits)""#,
"something (32 bits)",
"something ($WORD bits)",
)];
for &(input, expected_regex, expected_replacement) in good_data {
let parsed = parse_normalize_rule(input);
@ -56,6 +47,7 @@ fn test_parse_normalize_rule() {
}
let bad_data = &[
r#"normalize-stderr-32bit "something (32 bits)" -> "something ($WORD bits)""#,
r#"normalize-stderr-16bit: something (16 bits) -> something ($WORD bits)"#,
r#"normalize-stderr-32bit: something (32 bits) -> something ($WORD bits)"#,
r#"normalize-stderr-32bit: "something (32 bits) -> something ($WORD bits)"#,