|
39 | 39 | import com.couchbase.lite.support.action.ActionException; |
40 | 40 | import com.couchbase.lite.support.security.SymmetricKey; |
41 | 41 | import com.couchbase.lite.util.Log; |
42 | | -import com.fasterxml.jackson.core.JsonProcessingException; |
43 | 42 |
|
44 | 43 | import java.io.File; |
45 | 44 | import java.io.IOException; |
| 45 | +import java.io.UnsupportedEncodingException; |
46 | 46 | import java.math.BigInteger; |
| 47 | +import java.net.URLDecoder; |
| 48 | +import java.net.URLEncoder; |
47 | 49 | import java.util.ArrayList; |
48 | 50 | import java.util.HashMap; |
49 | 51 | import java.util.List; |
@@ -699,23 +701,53 @@ public void execute() throws ActionException { |
699 | 701 | // Internal (Protected/Private) Static Methods |
700 | 702 | /////////////////////////////////////////////////////////////////////////// |
701 | 703 |
|
702 | | - protected static String fileNameToViewName(String fileName) { |
| 704 | + protected static String fileNameToViewName(String fileName) throws CouchbaseLiteException { |
703 | 705 | if (!fileName.endsWith(kViewIndexPathExtension)) |
704 | | - return null; |
| 706 | + throw new CouchbaseLiteException(Status.BAD_PARAM); |
705 | 707 | if (fileName.startsWith(".")) |
706 | | - return null; |
| 708 | + throw new CouchbaseLiteException(Status.BAD_PARAM); |
| 709 | + |
707 | 710 | String viewName = fileName.substring(0, fileName.indexOf(".")); |
708 | | - viewName = viewName.replaceAll(":", "/"); |
| 711 | + viewName = isWindows() ? unescapeViewNameWindows(viewName) : viewName.replaceAll(":", "/"); |
709 | 712 | return viewName; |
710 | 713 | } |
711 | 714 |
|
712 | | - private static String viewNameToFileName(String viewName) { |
| 715 | + private static String viewNameToFileName(String viewName) throws CouchbaseLiteException { |
713 | 716 | if (viewName.startsWith(".") || viewName.indexOf(":") > 0) |
714 | | - return null; |
715 | | - viewName = viewName.replaceAll("/", ":"); |
| 717 | + throw new CouchbaseLiteException(Status.BAD_PARAM); |
| 718 | + |
| 719 | + viewName = isWindows() ? escapeViewNameWindows(viewName) : viewName.replaceAll("/", ":"); |
| 720 | + |
716 | 721 | return viewName + "." + kViewIndexPathExtension; |
717 | 722 | } |
718 | 723 |
|
| 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 | + } |
| 734 | + |
| 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 | + } |
| 745 | + private static String OS = System.getProperty("os.name").toLowerCase(); |
| 746 | + |
| 747 | + private static boolean isWindows(){ |
| 748 | + return (OS.indexOf("win") >= 0); |
| 749 | + } |
| 750 | + |
719 | 751 | /** |
720 | 752 | * Are key1 and key2 grouped together at this groupLevel? |
721 | 753 | */ |
|
0 commit comments