Skip to content

Commit

Permalink
Require non-alphanum leading up to a path replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Oct 12, 2021
1 parent da86ba7 commit e12b525
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/normalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,14 +320,24 @@ fn replace_case_insensitive(line: &str, pattern: &str, replacement: &str) -> Str
let line_lower = line_lower.as_str();
let mut split = line_lower.split(&pattern_lower);
let mut pos = 0;
let mut insert_replacement = false;
while let Some(keep) = split.next() {
if !replaced.is_empty() {
if insert_replacement {
replaced.push_str(replacement);
pos += pattern.len();
}
let keep = &line[pos..pos + keep.len()];
replaced.push_str(keep);
pos += keep.len();
insert_replacement = true;
if replaced.ends_with(|ch: char| ch.is_ascii_alphanumeric()) {
if let Some(ch) = line[pos..].chars().next() {
replaced.push(ch);
pos += ch.len_utf8();
split = line_lower[pos..].split(&pattern_lower);
insert_replacement = false;
}
}
}

replaced
Expand Down
2 changes: 1 addition & 1 deletion src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ Additional crates such as `pyo3-asyncio` can be used to integrate async Rust and
" "
error: `async fn` is not yet supported for Python functions.
Additional crates such as `pyo3-asyncio` can be used to integrate async Rust and Python. For more information, see https://github.com$DIR$WORKSPACE/issues/1632
Additional crates such as `pyo3-asyncio` can be used to integrate async Rust and Python. For more information, see https://github.com/PyO3/pyo3/issues/1632
--> tests/ui/invalid_pyfunctions.rs:10:1
|
10 | async fn async_function() {}
Expand Down

0 comments on commit e12b525

Please sign in to comment.