summaryrefslogtreecommitdiff
path: root/cli/lsp/path_to_regex.rs
diff options
context:
space:
mode:
authorKitson Kelly <me@kitsonkelly.com>2022-01-04 17:42:33 +1100
committerGitHub <noreply@github.com>2022-01-04 17:42:33 +1100
commit01ff7a87847a690546c62c7bd5c13823d3bb2d42 (patch)
tree41dcc362866d3b3fc19122e9f0d893c6aff65f2b /cli/lsp/path_to_regex.rs
parentd9b130410b78face988e2fa5c3939e3584bc02f7 (diff)
fix(lsp): handle repeating patterns in registry correctly (#13275)
Diffstat (limited to 'cli/lsp/path_to_regex.rs')
-rw-r--r--cli/lsp/path_to_regex.rs14
1 files changed, 11 insertions, 3 deletions
diff --git a/cli/lsp/path_to_regex.rs b/cli/lsp/path_to_regex.rs
index 16db88194..ef782c4db 100644
--- a/cli/lsp/path_to_regex.rs
+++ b/cli/lsp/path_to_regex.rs
@@ -249,7 +249,11 @@ impl StringOrVec {
}
}
- pub fn to_string(&self, maybe_key: Option<&Key>) -> String {
+ pub fn to_string(
+ &self,
+ maybe_key: Option<&Key>,
+ omit_initial_prefix: bool,
+ ) -> String {
match self {
Self::String(s) => s.clone(),
Self::Vec(v) => {
@@ -262,8 +266,12 @@ impl StringOrVec {
("/".to_string(), "".to_string())
};
let mut s = String::new();
- for segment in v {
- s.push_str(&format!("{}{}{}", prefix, segment, suffix));
+ for (i, segment) in v.iter().enumerate() {
+ if omit_initial_prefix && i == 0 {
+ s.push_str(&format!("{}{}", segment, suffix));
+ } else {
+ s.push_str(&format!("{}{}{}", prefix, segment, suffix));
+ }
}
s
}