From 672fa822c1d9955ef2cbadb36f322b4aa5c20873 Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Sun, 3 Nov 2024 11:16:50 -0600 Subject: [PATCH] sqf: fix lint s08 on escaped `%%` in format strings --- libs/sqf/src/analyze/lints/s08_format_args.rs | 7 +++---- libs/sqf/tests/lints/s08_format_args.sqf | 5 +++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/libs/sqf/src/analyze/lints/s08_format_args.rs b/libs/sqf/src/analyze/lints/s08_format_args.rs index d95e961f..e4ad15e8 100644 --- a/libs/sqf/src/analyze/lints/s08_format_args.rs +++ b/libs/sqf/src/analyze/lints/s08_format_args.rs @@ -116,6 +116,7 @@ fn get_format_problem(input: &str, extra_args: usize) -> Option { let mut token_active = false; let mut token_start = 0; for (i, c) in format.chars().enumerate() { + let outside_token = !token_active || i > token_start; if token_active && !c.is_ascii_digit() { token_active = false; if i > token_start { @@ -128,12 +129,10 @@ fn get_format_problem(input: &str, extra_args: usize) -> Option { .unwrap_or_default(); tokens.push(token_value); } else if c != '%' { - return Some(format!( - "format string: non-escaped \"%\" [at index {token_start}]" - )); + println!("format string: non-escaped \"%\" [at index {token_start}]"); } } - if !token_active && c == '%' { + if !token_active && c == '%' && outside_token { token_active = true; token_start = i + 1; } diff --git a/libs/sqf/tests/lints/s08_format_args.sqf b/libs/sqf/tests/lints/s08_format_args.sqf index 80e31e6c..08364112 100644 --- a/libs/sqf/tests/lints/s08_format_args.sqf +++ b/libs/sqf/tests/lints/s08_format_args.sqf @@ -7,3 +7,8 @@ format ["%1", 1, 2, 3]; // unused args format ["%1%2", 1]; // undefined tokens format ["%5", 1, 2 ,3 ,4, 5]; // skipped tokens formatText ["me too %1"]; + + +format ["%1%%", 100]; +format ["%%%1%%", 100]; +format ["%%%%%%%%%%%%%%%%"];