Skip to content

Commit

Permalink
fix(lsp): percent-encode host in deno: specifiers (#20811)
Browse files Browse the repository at this point in the history
  • Loading branch information
nayeemrmn committed Oct 6, 2023
1 parent f0608a5 commit 677a591
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions cli/lsp/urls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,16 +171,16 @@ impl LspUrlMap {
extension
)
} else {
let mut path =
specifier[..Position::BeforePath].replacen(":https://", "/", 1);
let parts: Vec<String> = specifier[Position::BeforePath..]
.split('/')
.map(|p| {
percent_encoding::utf8_percent_encode(p, COMPONENT).to_string()
})
.collect();
path.push_str(&parts.join("/"));
format!("deno:/{path}")
let mut str = String::with_capacity(specifier.as_str().len() + 6);
str.push_str("deno:/");
str.push_str(specifier.scheme());
for p in specifier[Position::BeforeHost..].split('/') {
str.push('/');
str.push_str(
&percent_encoding::utf8_percent_encode(p, COMPONENT).to_string(),
);
}
str
};
let url = LspClientUrl(Url::parse(&specifier_str)?);
inner.put(specifier.clone(), url.clone());
Expand Down Expand Up @@ -292,6 +292,22 @@ mod tests {
assert_eq!(actual_specifier, fixture);
}

#[test]
fn test_lsp_url_map_host_with_port() {
let map = LspUrlMap::default();
let fixture = resolve_url("http:https://localhost:8000/mod.ts").unwrap();
let actual_url = map
.normalize_specifier(&fixture)
.expect("could not handle specifier");
let expected_url =
Url::parse("deno:/http/localhost%3A8000/mod.ts").unwrap();
assert_eq!(actual_url.as_url(), &expected_url);

let actual_specifier =
map.normalize_url(actual_url.as_url(), LspUrlKind::File);
assert_eq!(actual_specifier, fixture);
}

#[cfg(windows)]
#[test]
fn test_normalize_windows_path() {
Expand Down

0 comments on commit 677a591

Please sign in to comment.