diff options
Diffstat (limited to 'support/texlab/crates/texlab/src/util.rs')
-rw-r--r-- | support/texlab/crates/texlab/src/util.rs | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/support/texlab/crates/texlab/src/util.rs b/support/texlab/crates/texlab/src/util.rs index c301dc7722..87e41a78ae 100644 --- a/support/texlab/crates/texlab/src/util.rs +++ b/support/texlab/crates/texlab/src/util.rs @@ -18,9 +18,28 @@ pub fn normalize_uri(uri: &mut lsp_types::Url) { } } + uri.set_path(&normalize_percent_encoding(uri.path())); uri.set_fragment(None); } +fn normalize_percent_encoding(input: &str) -> String { + let mut output = String::new(); + let mut i = 0; + for c in input.chars() { + if c == '%' && i == 0 { + output.push(c); + i = 2; + } else if i > 0 { + output.push(c.to_ascii_uppercase()); + i -= 1; + } else { + output.push(c); + } + } + + output +} + fn fix_drive_letter(text: &str) -> Option<String> { if !text.is_ascii() || text.is_empty() { return None; @@ -59,4 +78,44 @@ mod tests { normalize_uri(&mut uri); assert_eq!(uri.as_str(), "foo:///bar/baz.txt"); } + + #[test] + #[cfg(unix)] + fn test_lowercase_percent_encoding_unix() { + let mut uri1 = Url::parse("file:///foo/%c3%a4.tex").unwrap(); + let uri2 = Url::from_file_path("/foo/ä.tex").unwrap(); + + normalize_uri(&mut uri1); + assert_eq!(uri1, uri2); + } + + #[test] + #[cfg(unix)] + fn test_uppercase_percent_encoding_unix() { + let mut uri1 = Url::parse("file:///foo/%C3%A4.tex").unwrap(); + let uri2 = Url::from_file_path("/foo/ä.tex").unwrap(); + + normalize_uri(&mut uri1); + assert_eq!(uri1, uri2); + } + + #[test] + #[cfg(windows)] + fn test_lowercase_percent_encoding_windows() { + let mut uri1 = Url::parse("file:///c%3a/foo/%c3%a4.tex").unwrap(); + let uri2 = Url::from_file_path("C:/foo/ä.tex").unwrap(); + + normalize_uri(&mut uri1); + assert_eq!(uri1, uri2); + } + + #[test] + #[cfg(windows)] + fn test_uppercase_percent_encoding_windows() { + let mut uri1 = Url::parse("file:///c%3A/foo/%C3%A4.tex").unwrap(); + let uri2 = Url::from_file_path("C:/foo/ä.tex").unwrap(); + + normalize_uri(&mut uri1); + assert_eq!(uri1, uri2); + } } |