Skip to content

Commit

Permalink
resolve issue with trailing escaped commas in scriptlet arguments
Browse files Browse the repository at this point in the history
Discovered from `pravda.com.ua,epravda.com.ua##+js(remove-node-text, script, \,mr=function(r\,)` in Adguard Russian
  • Loading branch information
antonok-edm committed Feb 20, 2024
1 parent dd970f2 commit 9aa8bce
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/resources/resource_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,13 @@ fn index_next_unescaped_separator(s: &str, separator: char) -> (Option<usize>, b
return (None, needs_transform)
}
}
(Some(new_arg_end), needs_transform)
// don't index beyond the end of the string
let new_arg_end = if new_arg_end >= s.len() {
None
} else {
Some(new_arg_end)
};
(new_arg_end, needs_transform)
}

/// Replaces escaped instances of `separator` in `arg` with unescaped characters.
Expand Down Expand Up @@ -467,6 +473,8 @@ mod arg_parsing_util_tests {
assert_eq!(index_next_unescaped_separator(r#"\`\\\``"#, '`'), (Some(6), true));
assert_eq!(index_next_unescaped_separator(r#"\\\`\``"#, '`'), (Some(6), true));
assert_eq!(index_next_unescaped_separator(r#"\\\`\\``"#, '`'), (Some(6), true));

assert_eq!(index_next_unescaped_separator(r#"\,test\,"#, ','), (None, true))
}

#[test]
Expand Down Expand Up @@ -615,6 +623,12 @@ mod scriptlet_storage_tests {
assert_eq!(args, None);
}

#[test]
fn parse_argslist_trailing_escaped_comma() {
let args = parse_scriptlet_args(r#"remove-node-text, script, \,mr=function(r\,"#).unwrap();
assert_eq!(args, vec!["remove-node-text", "script", ",mr=function(r,"]);
}

#[test]
fn get_patched_scriptlets() {
let resources = ResourceStorage::from_resources([
Expand Down

0 comments on commit 9aa8bce

Please sign in to comment.