Skip to content

Commit ce0e1ac

Browse files
committed
♻️ Use Patter.quote() in all replaceFirst() and replaceAll() invocations
1 parent 48af0cd commit ce0e1ac

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

commons/src/main/java/org/restheart/security/AclVarsInterpolator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,12 +276,12 @@ static String interpolatePredicate(String predicate, String prefix, BsonDocument
276276
// interpolate primitive values
277277
flatten.keySet().stream().filter(key -> flatten.get(key) != null)
278278
.filter(key -> isJsonPrimitive(flatten.get(key)))
279-
.forEach(key -> ret[0] = ret[0].replaceAll(prefix.concat(key), quote(jsonPrimitiveValue(flatten.get(key)))));
279+
.forEach(key -> ret[0] = ret[0].replaceAll(Pattern.quote(prefix.concat(key)), quote(jsonPrimitiveValue(flatten.get(key)))));
280280

281281
// interpolate arrays
282282
flatten.keySet().stream().filter(key -> flatten.get(key) != null)
283283
.filter(key -> isJsonArray(flatten.get(key)))
284-
.forEach(key -> ret[0] = ret[0].replaceAll(prefix.concat(key), jsonArrayValue(flatten.get(key).asArray())));
284+
.forEach(key -> ret[0] = ret[0].replaceAll(Pattern.quote(prefix.concat(key)), jsonArrayValue(flatten.get(key).asArray())));
285285

286286
// remove unboud variables
287287
flatten.keySet().stream().forEach(key -> ret[0] = removeUnboundVariables(prefix, ret[0]));

commons/src/main/java/org/restheart/utils/ResourcesExtractor.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
import java.nio.file.attribute.BasicFileAttributes;
3535
import java.util.HashMap;
3636
import java.util.Map;
37+
import java.util.regex.Pattern;
38+
3739
import org.slf4j.Logger;
3840
import org.slf4j.LoggerFactory;
3941

@@ -77,6 +79,7 @@ public static void deleteTempDir(Class clazz, String resourcePath, File tempDir)
7779

7880
/**
7981
*
82+
* @param clazz
8083
* @param resourcePath
8184
* @return
8285
* @throws java.io.IOException
@@ -127,7 +130,7 @@ private FileVisitResult copy(Path fileOrDir) throws IOException {
127130
return FileVisitResult.CONTINUE;
128131
}
129132

130-
Path destination = Paths.get(destinationDir.toString(), fileOrDir.toString().replaceAll(resourcePath + "/", ""));
133+
Path destination = Paths.get(destinationDir.toString(), fileOrDir.toString().replaceAll(Pattern.quote(resourcePath) + "/", ""));
131134

132135
Files.copy(fileOrDir, destination, StandardCopyOption.REPLACE_EXISTING);
133136
return FileVisitResult.CONTINUE;

commons/src/main/java/org/restheart/utils/URLUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public static String getParentPath(String path) {
130130
* @return the prefix url of the exchange
131131
*/
132132
public static String getPrefixUrl(HttpServerExchange exchange) {
133-
return exchange.getRequestURL().replaceAll(exchange.getRelativePath(), "");
133+
return exchange.getRequestURL().replaceAll(Pattern.quote(exchange.getRelativePath()), "");
134134
}
135135

136136
/**

0 commit comments

Comments
 (0)