-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
query service operations by names (#285)
* query service operations by names * fix regex problem
- Loading branch information
Showing
4 changed files
with
61 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
arex-storage-config/src/main/java/com/arextest/config/utils/RegexUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.arextest.config.utils; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
/** | ||
* @author b_yu | ||
* @since 2024/12/20 | ||
*/ | ||
|
||
public class RegexUtils { | ||
|
||
private static final Set<Character> SPECIAL_CHARS = new HashSet<>(); | ||
|
||
static { | ||
char[] specialCharsArray = {'.', '\\', '+', '*', '?', '[', '^', ']', '$', '(', ')', '{', '}', | ||
'=', '!', '<', '>', '|', ':', '-'}; | ||
for (char c : specialCharsArray) { | ||
SPECIAL_CHARS.add(c); | ||
} | ||
} | ||
|
||
public static String getRegexForFuzzySearch(String keyword) { | ||
if (keyword == null || keyword.isEmpty()) { | ||
return keyword; | ||
} | ||
return ".*?" + escapeSpecialChars(keyword) + ".*"; | ||
} | ||
|
||
private static String escapeSpecialChars(String keyword) { | ||
if (keyword == null || keyword.isEmpty()) { | ||
return keyword; | ||
} | ||
StringBuilder escapedKeyword = new StringBuilder(); | ||
for (char c : keyword.toCharArray()) { | ||
if (SPECIAL_CHARS.contains(c)) { | ||
escapedKeyword.append('\\'); | ||
} | ||
escapedKeyword.append(c); | ||
} | ||
return escapedKeyword.toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ logging: | |
arex: | ||
storage: | ||
enableDiscoveryEntryPoint: true | ||
mongodbUri: mongodb://arex:[email protected]:37017/arex_storage_db | ||
mongodbUri: ${arex.mongo.uri:mongodb://arex:[email protected]:37017/arex_storage_db} | ||
recordEnv: TEST | ||
expirationDurationMap: | ||
ConfigFile: 3456000000 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters