From 92a9580d09a61f7be671bb8a2ce898118b38f74b Mon Sep 17 00:00:00 2001 From: Scott Davey Date: Mon, 4 Oct 2021 15:59:51 +1100 Subject: [PATCH] Ported include/exclude logic from upstream --- .../com/crypt/cordova/DecryptResource.java | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/android/com/crypt/cordova/DecryptResource.java b/src/android/com/crypt/cordova/DecryptResource.java index 2cd9b51..fde3c45 100644 --- a/src/android/com/crypt/cordova/DecryptResource.java +++ b/src/android/com/crypt/cordova/DecryptResource.java @@ -14,6 +14,7 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStreamReader; +import java.util.regex.Pattern; import javax.crypto.Cipher; import javax.crypto.SecretKey; @@ -28,12 +29,8 @@ public class DecryptResource extends CordovaPlugin { private static final String CRYPT_KEY = ""; private static final String CRYPT_IV = ""; - private static final String[] CRYPT_FILES = { - ".htm", - ".html", - ".js", - ".css", - }; + private static final String[] INCLUDE_FILES = new String[] { }; + private static final String[] EXCLUDE_FILES = new String[] { }; private String URL_PREFIX; private String launchUri; @@ -102,12 +99,23 @@ private String tofileUri(String uri) { return uri; } - private boolean isCryptFiles(String uri) { - for (String ext: CRYPT_FILES) { - if (uri.endsWith(ext)) { - return true; + private boolean isCryptFiles(String uri) { + String checkPath = uri.replace("file:///android_asset/www/", ""); + if (!this.hasMatch(checkPath, INCLUDE_FILES)) { + return false; + } + if (this.hasMatch(checkPath, EXCLUDE_FILES)) { + return false; } + return true; + } + + private boolean hasMatch(String text, String[] regexArr) { + for (String regex : regexArr) { + if (Pattern.compile(regex).matcher(text).find()) { + return true; + } + } + return false; } - return false; - } }