Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sqf: fix lint s08 on escaped %% in format strings #823

Merged
merged 2 commits into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions libs/sqf/src/analyze/lints/s08_format_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ fn get_format_problem(input: &str, extra_args: usize) -> Option<String> {
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 {
Expand All @@ -128,12 +129,10 @@ fn get_format_problem(input: &str, extra_args: usize) -> Option<String> {
.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}]");
BrettMayson marked this conversation as resolved.
Show resolved Hide resolved
}
}
if !token_active && c == '%' {
if !token_active && c == '%' && outside_token {
token_active = true;
token_start = i + 1;
}
Expand Down
5 changes: 5 additions & 0 deletions libs/sqf/tests/lints/s08_format_args.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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 ["%%%%%%%%%%%%%%%%"];
Loading