From 5732bdcd941088b36ba3a4614860d2c3c2abf56b Mon Sep 17 00:00:00 2001 From: Andrew Phillips Date: Tue, 22 Jul 2014 10:25:51 -0400 Subject: [PATCH] Escaping regex special chars (esp. '\') in delimiter matching Uncovered by 370194b --- .../main/java/org/jclouds/blobstore/LocalAsyncBlobStore.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/blobstore/src/main/java/org/jclouds/blobstore/LocalAsyncBlobStore.java b/blobstore/src/main/java/org/jclouds/blobstore/LocalAsyncBlobStore.java index 88117e42fb..a411e21d3a 100644 --- a/blobstore/src/main/java/org/jclouds/blobstore/LocalAsyncBlobStore.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/LocalAsyncBlobStore.java @@ -33,6 +33,7 @@ import java.io.IOException; import java.util.Date; import java.util.Set; import java.util.SortedSet; +import java.util.regex.Pattern; import javax.annotation.Resource; import javax.inject.Inject; @@ -332,7 +333,7 @@ public class LocalAsyncBlobStore extends BaseAsyncBlobStore { // ensure we don't accidentally append twice String toMatch = prefix.endsWith("/") ? prefix : prefix + delimiter; if (metadata.getName().startsWith(toMatch)) { - String unprefixedName = metadata.getName().replaceFirst(toMatch, ""); + String unprefixedName = metadata.getName().replaceFirst(Pattern.quote(toMatch), ""); if (unprefixedName.equals("")) { // we are the prefix in this case, return false return false; @@ -359,7 +360,7 @@ public class LocalAsyncBlobStore extends BaseAsyncBlobStore { // ensure we don't accidentally append twice String toMatch = prefix.endsWith("/") ? prefix : prefix + delimiter; if (working.startsWith(toMatch)) { - working = working.replaceFirst(toMatch, ""); + working = working.replaceFirst(Pattern.quote(toMatch), ""); } } if (working.contains(delimiter)) {