这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ impl ResolveError {
/// Error for [ResolveError::Specifier]
#[derive(Debug, Clone, Eq, PartialEq, Error)]
pub enum SpecifierError {
#[error("The specifiers must be a non-empty string. Received ''")]
Empty,
#[error("The specifiers must be a non-empty string. Received \"{0}\"")]
Empty(String),
}

/// JSON error from [serde_json::Error]
Expand Down
6 changes: 5 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,11 @@ impl<Fs: FileSystem + Default> ResolverGeneric<Fs> {
let mut extended_tsconfig_paths = vec![];
for tsconfig_extend_specifier in &tsconfig.extends {
let extended_tsconfig_path = match tsconfig_extend_specifier.as_bytes().first() {
None => return Err(ResolveError::Specifier(SpecifierError::Empty)),
None => {
return Err(ResolveError::Specifier(SpecifierError::Empty(
tsconfig_extend_specifier.to_string(),
)))
}
Some(b'/') => PathBuf::from(tsconfig_extend_specifier),
Some(b'.') => tsconfig.directory().normalize_with(tsconfig_extend_specifier),
_ => self
Expand Down
14 changes: 11 additions & 3 deletions src/specifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@ impl<'a> Specifier<'a> {

pub fn parse(specifier: &'a str) -> Result<Specifier<'a>, SpecifierError> {
if specifier.is_empty() {
return Err(SpecifierError::Empty);
return Err(SpecifierError::Empty(specifier.to_string()));
}
let offset = match specifier.as_bytes()[0] {
b'/' | b'.' | b'#' => 1,
_ => 0,
};
let (path, query, fragment) = Self::parse_query_framgment(specifier, offset);
if path.is_empty() {
return Err(SpecifierError::Empty(specifier.to_string()));
}
Ok(Self { path, query, fragment })
}

Expand Down Expand Up @@ -81,8 +84,13 @@ mod tests {

#[test]
fn empty() {
let specifier = "";
assert_eq!(Specifier::parse(specifier), Err(SpecifierError::Empty));
let specifiers = ["", "?"];
for specifier in specifiers {
assert_eq!(
Specifier::parse(specifier),
Err(SpecifierError::Empty(specifier.to_string()))
);
}
}

#[test]
Expand Down