1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-25 15:29:32 -05:00

fix(lsp): only resolve sources with supported schemas (#8696)

Fixes #8695
This commit is contained in:
Kitson Kelly 2020-12-10 11:12:46 +11:00 committed by GitHub
parent de65312b7f
commit 1a72c9ba23
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 2 deletions

View file

@ -26,7 +26,7 @@ use std::pin::Pin;
use std::sync::Arc;
use std::sync::Mutex;
const SUPPORTED_SCHEMES: [&str; 3] = ["http", "https", "file"];
pub const SUPPORTED_SCHEMES: [&str; 3] = ["http", "https", "file"];
/// A structure representing a source file.
#[derive(Debug, Clone, Eq, PartialEq)]

View file

@ -5,6 +5,7 @@ use super::text;
use crate::file_fetcher::get_source_from_bytes;
use crate::file_fetcher::map_content_type;
use crate::file_fetcher::SUPPORTED_SCHEMES;
use crate::http_cache;
use crate::http_cache::HttpCache;
use crate::import_map::ImportMap;
@ -279,7 +280,12 @@ impl Sources {
&mut self,
specifier: &ModuleSpecifier,
) -> Option<ModuleSpecifier> {
if specifier.as_url().scheme() == "file" {
let scheme = specifier.as_url().scheme();
if !SUPPORTED_SCHEMES.contains(&scheme) {
return None;
}
if scheme == "file" {
if let Ok(path) = specifier.as_url().to_file_path() {
if path.is_file() {
return Some(specifier.clone());
@ -377,4 +383,13 @@ mod tests {
let actual = actual.unwrap();
assert_eq!(actual, 28);
}
#[test]
fn test_sources_resolve_specifier_non_supported_schema() {
let (mut sources, _) = setup();
let specifier = ModuleSpecifier::resolve_url("foo://a/b/c.ts")
.expect("could not create specifier");
let actual = sources.resolve_specifier(&specifier);
assert!(actual.is_none());
}
}