@@ -5,6 +5,7 @@ use collections::HashMap;
55use futures:: future:: join_all;
66use gpui:: { App , AppContext , AsyncApp , Task } ;
77use http_client:: github:: { AssetKind , GitHubLspBinaryVersion , build_asset_url} ;
8+ use itertools:: Itertools as _;
89use language:: {
910 ContextLocation , ContextProvider , File , LanguageName , LanguageToolchainStore , LspAdapter ,
1011 LspAdapterDelegate , LspInstaller , Toolchain ,
@@ -18,7 +19,7 @@ use std::{
1819 borrow:: Cow ,
1920 ffi:: OsString ,
2021 path:: { Path , PathBuf } ,
21- sync:: Arc ,
22+ sync:: { Arc , LazyLock } ,
2223} ;
2324use task:: { TaskTemplate , TaskTemplates , VariableName } ;
2425use util:: merge_json_value_into;
@@ -511,9 +512,9 @@ fn eslint_server_binary_arguments(server_path: &Path) -> Vec<OsString> {
511512}
512513
513514fn replace_test_name_parameters ( test_name : & str ) -> String {
514- let pattern = regex:: Regex :: new ( r"(%|\$)[0-9a-zA-Z]+" ) . unwrap ( ) ;
515-
516- regex:: escape ( & pattern . replace_all ( test_name , "(.+?)" ) )
515+ static PATTERN : LazyLock < regex:: Regex > =
516+ LazyLock :: new ( || regex :: Regex :: new ( r"(\$([A-Za-z0-9_\.]+|[\#])|%[psdifjo#\$%])" ) . unwrap ( ) ) ;
517+ PATTERN . split ( test_name ) . map ( regex:: escape) . join ( "(.+?)" )
517518}
518519
519520pub struct TypeScriptLspAdapter {
@@ -1015,7 +1016,9 @@ mod tests {
10151016 use unindent:: Unindent ;
10161017 use util:: path;
10171018
1018- use crate :: typescript:: { PackageJsonData , TypeScriptContextProvider } ;
1019+ use crate :: typescript:: {
1020+ PackageJsonData , TypeScriptContextProvider , replace_test_name_parameters,
1021+ } ;
10191022
10201023 #[ gpui:: test]
10211024 async fn test_outline ( cx : & mut TestAppContext ) {
@@ -1227,4 +1230,37 @@ mod tests {
12271230 ]
12281231 ) ;
12291232 }
1233+ #[ test]
1234+ fn test_escaping_name ( ) {
1235+ let cases = [
1236+ ( "plain test name" , "plain test name" ) ,
1237+ ( "test name with $param_name" , "test name with (.+?)" ) ,
1238+ ( "test name with $nested.param.name" , "test name with (.+?)" ) ,
1239+ ( "test name with $#" , "test name with (.+?)" ) ,
1240+ ( "test name with $##" , "test name with (.+?)\\ #" ) ,
1241+ ( "test name with %p" , "test name with (.+?)" ) ,
1242+ ( "test name with %s" , "test name with (.+?)" ) ,
1243+ ( "test name with %d" , "test name with (.+?)" ) ,
1244+ ( "test name with %i" , "test name with (.+?)" ) ,
1245+ ( "test name with %f" , "test name with (.+?)" ) ,
1246+ ( "test name with %j" , "test name with (.+?)" ) ,
1247+ ( "test name with %o" , "test name with (.+?)" ) ,
1248+ ( "test name with %#" , "test name with (.+?)" ) ,
1249+ ( "test name with %$" , "test name with (.+?)" ) ,
1250+ ( "test name with %%" , "test name with (.+?)" ) ,
1251+ ( "test name with %q" , "test name with %q" ) ,
1252+ (
1253+ "test name with regex chars .*+?^${}()|[]\\ " ,
1254+ "test name with regex chars \\ .\\ *\\ +\\ ?\\ ^\\ $\\ {\\ }\\ (\\ )\\ |\\ [\\ ]\\ \\ " ,
1255+ ) ,
1256+ (
1257+ "test name with multiple $params and %pretty and %b and (.+?)" ,
1258+ "test name with multiple (.+?) and (.+?)retty and %b and \\ (\\ .\\ +\\ ?\\ )" ,
1259+ ) ,
1260+ ] ;
1261+
1262+ for ( input, expected) in cases {
1263+ assert_eq ! ( replace_test_name_parameters( input) , expected) ;
1264+ }
1265+ }
12301266}
0 commit comments