summaryrefslogtreecommitdiff
path: root/cli/lsp/path_to_regex.rs
diff options
context:
space:
mode:
authorKitson Kelly <me@kitsonkelly.com>2022-01-02 16:27:19 +1100
committerGitHub <noreply@github.com>2022-01-02 16:27:19 +1100
commit2e72893fa2da175f5949c0c5c6760d404fa65a23 (patch)
treed86c98fd445eeb5a93ef29251e9a5f8c71d82aa3 /cli/lsp/path_to_regex.rs
parent0ae46a975cd32301ee01df4eafb23c9db52f1198 (diff)
fix(lsp): better handling of folders in registry completions (#13250)
Diffstat (limited to 'cli/lsp/path_to_regex.rs')
-rw-r--r--cli/lsp/path_to_regex.rs29
1 files changed, 28 insertions, 1 deletions
diff --git a/cli/lsp/path_to_regex.rs b/cli/lsp/path_to_regex.rs
index 393591785..16db88194 100644
--- a/cli/lsp/path_to_regex.rs
+++ b/cli/lsp/path_to_regex.rs
@@ -733,7 +733,7 @@ impl Compiler {
let prefix = k.prefix.clone().unwrap_or_default();
let suffix = k.suffix.clone().unwrap_or_default();
for segment in v {
- if self.validate {
+ if !segment.is_empty() && self.validate {
if let Some(re) = &self.matches[i] {
if !re.is_match(segment) {
return Err(anyhow!(
@@ -912,6 +912,33 @@ mod tests {
}
#[test]
+ fn test_compiler_ends_with_sep() {
+ let tokens = parse("/x/:a@:b/:c*", None).expect("could not parse");
+ let mut params = HashMap::<StringOrNumber, StringOrVec>::new();
+ params.insert(
+ StringOrNumber::String("a".to_string()),
+ StringOrVec::String("y".to_string()),
+ );
+ params.insert(
+ StringOrNumber::String("b".to_string()),
+ StringOrVec::String("v1.0.0".to_string()),
+ );
+ params.insert(
+ StringOrNumber::String("c".to_string()),
+ StringOrVec::Vec(vec![
+ "z".to_string(),
+ "example".to_string(),
+ "".to_string(),
+ ]),
+ );
+ let compiler = Compiler::new(&tokens, None);
+ let actual = compiler.to_path(&params);
+ assert!(actual.is_ok());
+ let actual = actual.unwrap();
+ assert_eq!(actual, "/x/y@v1.0.0/z/example/".to_string());
+ }
+
+ #[test]
fn test_string_to_regex() {
test_path("/", None, &[("/test", None), ("/", Some(("/", 0, 1)))]);
test_path(