aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-db-dao
diff options
context:
space:
mode:
authorFranck Arnulfo <franck.arnulfo@gmail.com>2019-05-31 11:55:03 +0200
committersonartech <sonartech@sonarsource.com>2019-06-28 08:45:52 +0200
commite74f2a8c8bc791eae8ff6f9f5f8210a3068c44ae (patch)
treea1cb5706c30014dbd0d3d2c7ffec7c363f5b9d4d /server/sonar-db-dao
parent3a1a6e9107f42b4689a1b5d3ce09f770dbb46bda (diff)
downloadsonarqube-e74f2a8c8bc791eae8ff6f9f5f8210a3068c44ae.tar.gz
sonarqube-e74f2a8c8bc791eae8ff6f9f5f8210a3068c44ae.zip
Replace 3 regex with 1 and precompiled pattern
Diffstat (limited to 'server/sonar-db-dao')
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/DaoUtils.java10
1 files changed, 6 insertions, 4 deletions
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/DaoUtils.java b/server/sonar-db-dao/src/main/java/org/sonar/db/DaoUtils.java
index 6ba6d6be80f..2d5ff4e4019 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/DaoUtils.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/DaoUtils.java
@@ -19,7 +19,10 @@
*/
package org.sonar.db;
+import java.util.regex.Pattern;
+
public class DaoUtils {
+ private static final Pattern ESCAPE_PERCENT_AND_UNDERSCORE = Pattern.compile("[/%_]");
private DaoUtils() {
// prevent new instances
@@ -55,9 +58,8 @@ public class DaoUtils {
* Replace escape percent and underscore by adding a slash just before
*/
private static String escapePercentAndUnderscore(String value) {
- return value
- .replaceAll("/", "//")
- .replaceAll("%", "/%")
- .replaceAll("_", "/_");
+ return ESCAPE_PERCENT_AND_UNDERSCORE.matcher(value)
+ // $0 : Group zero, stands for the entire expression
+ .replaceAll("/$0");
}
}