Skip to content

Commit

Permalink
Merge pull request #135 from dtolnay/replace
Browse files Browse the repository at this point in the history
Fix unexpected dir substitution in url
  • Loading branch information
dtolnay authored Oct 12, 2021
2 parents 498db7b + e12b525 commit c110590
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 8 deletions.
26 changes: 21 additions & 5 deletions src/normalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,13 +316,29 @@ fn replace_case_insensitive(line: &str, pattern: &str, replacement: &str) -> Str
let line_lower = line.to_ascii_lowercase().replace('\\', "/");
let pattern_lower = pattern.to_ascii_lowercase().replace('\\', "/");
let mut replaced = String::with_capacity(line.len());
for (i, keep) in line_lower.split(&pattern_lower).enumerate() {
if i > 0 {

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 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;
}
}
let begin = replaced.len() - i * replacement.len() + i * pattern.len();
let end = begin + keep.len();
replaced.push_str(&line[begin..end]);
}

replaced
}
27 changes: 24 additions & 3 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ use crate::directory::Directory;
use crate::run::PathDependency;

macro_rules! test_normalize {
($name:ident $original:literal $expected:literal) => {
($name:ident $(DIR=$dir:literal)? $(WORKSPACE=$workspace:literal)? $original:literal $expected:literal) => {
#[test]
fn $name() {
let context = super::Context {
krate: "trybuild000",
source_dir: &Directory::new("/git/trybuild/test_suite"),
workspace: &Directory::new("/git/trybuild"),
source_dir: &Directory::new({ "/git/trybuild/test_suite" $(; $dir)? }),
workspace: &Directory::new({ "/git/trybuild" $(; $workspace)? }),
path_dependencies: &[PathDependency {
name: String::from("diesel"),
normalized_path: Directory::new("/home/user/documents/rust/diesel/diesel"),
Expand Down Expand Up @@ -248,3 +248,24 @@ note: the following traits must be implemented
| |_^
= note: this error originates in the macro `anyhow` (in Nightly builds, run with -Z macro-backtrace for more info)
"}

test_normalize! {test_pyo3_url
DIR="/pyo3"
WORKSPACE="/pyo3"
"
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/PyO3/pyo3/issues/1632
--> tests/ui/invalid_pyfunctions.rs:10:1
|
10 | async fn async_function() {}
| ^^^^^
" "
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/PyO3/pyo3/issues/1632
--> tests/ui/invalid_pyfunctions.rs:10:1
|
10 | async fn async_function() {}
| ^^^^^
"}

0 comments on commit c110590

Please sign in to comment.