Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Do not escape glob pattern in dynamic Jest/Vitest test names (#36999)
Alexander1c27a6dbc2f7
diff --git a/Cargo.lock b/Cargo.lockindex 65e57c3c9bc..db61ba7b121 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -9292,6 +9292,7 @@ dependencies = ["futures 0.3.31","gpui","http_client",+ "itertools 0.14.0","language","log","lsp",diff --git a/crates/languages/Cargo.toml b/crates/languages/Cargo.tomlindex 44b0cb58653..7ebafd8fdd9 100644--- a/crates/languages/Cargo.toml+++ b/crates/languages/Cargo.toml@@ -45,6 +45,7 @@ dap.workspace = truefutures.workspace = truegpui.workspace = truehttp_client.workspace = true+itertools.workspace = truelanguage.workspace = truelog.workspace = truelsp.workspace = truediff --git a/crates/languages/src/typescript.rs b/crates/languages/src/typescript.rsindex bc939f0b727..edfddd3f76e 100644--- a/crates/languages/src/typescript.rs+++ b/crates/languages/src/typescript.rs@@ -5,6 +5,7 @@ use collections::HashMap;use futures::future::join_all;use gpui::{App, AppContext, AsyncApp, Task};use http_client::github::{AssetKind, GitHubLspBinaryVersion, build_asset_url};+use itertools::Itertools as _;use language::{ContextLocation, ContextProvider, File, LanguageName, LanguageToolchainStore, LspAdapter,LspAdapterDelegate, LspInstaller, Toolchain,@@ -18,7 +19,7 @@ use std::{borrow::Cow,ffi::OsString,path::{Path, PathBuf},- sync::Arc,+ sync::{Arc, LazyLock},};use task::{TaskTemplate, TaskTemplates, VariableName};use util::merge_json_value_into;@@ -511,9 +512,9 @@ fn eslint_server_binary_arguments(server_path: &Path) -> Vec<OsString> {}fn replace_test_name_parameters(test_name: &str) -> String {- let pattern = regex::Regex::new(r"(%|\$)[0-9a-zA-Z]+").unwrap();-- regex::escape(&pattern.replace_all(test_name, "(.+?)"))+ static PATTERN: LazyLock<regex::Regex> =+ LazyLock::new(|| regex::Regex::new(r"(\$([A-Za-z0-9_\.]+|[\#])|%[psdifjo#\$%])").unwrap());+ PATTERN.split(test_name).map(regex::escape).join("(.+?)")}pub struct TypeScriptLspAdapter {@@ -1015,7 +1016,9 @@ mod tests {use unindent::Unindent;use util::path;- use crate::typescript::{PackageJsonData, TypeScriptContextProvider};+ use crate::typescript::{+ PackageJsonData, TypeScriptContextProvider, replace_test_name_parameters,+ };#[gpui::test]async fn test_outline(cx: &mut TestAppContext) {@@ -1227,4 +1230,37 @@ mod tests {]);}+ #[test]+ fn test_escaping_name() {+ let cases = [+ ("plain test name", "plain test name"),+ ("test name with $param_name", "test name with (.+?)"),+ ("test name with $nested.param.name", "test name with (.+?)"),+ ("test name with $#", "test name with (.+?)"),+ ("test name with $##", "test name with (.+?)\\#"),+ ("test name with %p", "test name with (.+?)"),+ ("test name with %s", "test name with (.+?)"),+ ("test name with %d", "test name with (.+?)"),+ ("test name with %i", "test name with (.+?)"),+ ("test name with %f", "test name with (.+?)"),+ ("test name with %j", "test name with (.+?)"),+ ("test name with %o", "test name with (.+?)"),+ ("test name with %#", "test name with (.+?)"),+ ("test name with %$", "test name with (.+?)"),+ ("test name with %%", "test name with (.+?)"),+ ("test name with %q", "test name with %q"),+ (+ "test name with regex chars .*+?^${}()|[]\\",+ "test name with regex chars \\.\\*\\+\\?\\^\\$\\{\\}\\(\\)\\|\\[\\]\\\\",+ ),+ (+ "test name with multiple $params and %pretty and %b and (.+?)",+ "test name with multiple (.+?) and (.+?)retty and %b and \\(\\.\\+\\?\\)",+ ),+ ];++ for (input, expected) in cases {+ assert_eq!(replace_test_name_parameters(input), expected);+ }+ }}