Skip to content
This repository was archived by the owner on Mar 9, 2022. It is now read-only.

Commit 5218bea

Browse files
author
Hideki Itakura
committed
support asterisk '*' as regal character for windows
1 parent 5ebddcd commit 5218bea

1 file changed

Lines changed: 22 additions & 13 deletions

File tree

src/main/java/com/couchbase/lite/store/ForestDBViewStore.java

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -708,31 +708,40 @@ protected static String fileNameToViewName(String fileName) throws CouchbaseLite
708708
throw new CouchbaseLiteException(Status.BAD_PARAM);
709709

710710
String viewName = fileName.substring(0, fileName.indexOf("."));
711-
try {
712-
viewName = isWindows() ? URLDecoder.decode(viewName, "UTF-8") : viewName.replaceAll(":", "/");
713-
} catch (UnsupportedEncodingException ex) {
714-
Log.w(TAG, "Error to url encode: " + viewName, ex);
715-
throw new CouchbaseLiteException(ex, Status.BAD_ENCODING);
716-
}
711+
viewName = isWindows() ? unescapeViewNameWindows(viewName) : viewName.replaceAll(":", "/");
717712
return viewName;
718713
}
719714

720715
private static String viewNameToFileName(String viewName) throws CouchbaseLiteException {
721716
if (viewName.startsWith(".") || viewName.indexOf(":") > 0)
722717
throw new CouchbaseLiteException(Status.BAD_PARAM);
723718

724-
try {
725-
viewName = isWindows() ? URLEncoder.encode(viewName, "UTF-8") : viewName.replaceAll("/", ":");
726-
} catch (UnsupportedEncodingException ex) {
727-
Log.w(TAG, "Error to url decode: " + viewName, ex);
728-
throw new CouchbaseLiteException(ex, Status.BAD_ENCODING);
729-
}
719+
viewName = isWindows() ? escapeViewNameWindows(viewName) : viewName.replaceAll("/", ":");
730720

731721
return viewName + "." + kViewIndexPathExtension;
732722
}
733723

724+
private static String escapeViewNameWindows(String viewName)throws CouchbaseLiteException {
725+
try {
726+
viewName = URLEncoder.encode(viewName, "UTF-8");
727+
} catch (UnsupportedEncodingException e) {
728+
Log.w(TAG, "Error to url decode: " + viewName, e);
729+
throw new CouchbaseLiteException(e, Status.BAD_ENCODING);
730+
}
731+
viewName = viewName.replaceAll("\\*", "%2A");
732+
return viewName;
733+
}
734734

735-
735+
private static String unescapeViewNameWindows(String viewName)throws CouchbaseLiteException {
736+
viewName = viewName.replaceAll("%2A", "*");
737+
try {
738+
viewName = URLDecoder.decode(viewName, "UTF-8");
739+
} catch (UnsupportedEncodingException e) {
740+
Log.w(TAG, "Error to url decode: " + viewName, e);
741+
throw new CouchbaseLiteException(e, Status.BAD_ENCODING);
742+
}
743+
return viewName;
744+
}
736745
private static String OS = System.getProperty("os.name").toLowerCase();
737746

738747
private static boolean isWindows(){

0 commit comments

Comments
 (0)