Skip to content

Commit

Permalink
check mmapID with "/"
Browse files Browse the repository at this point in the history
  • Loading branch information
lingol committed Oct 9, 2018
1 parent 67690d7 commit 9c75909
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions Android/MMKV/mmkv/src/main/java/com/tencent/mmkv/MMKV.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public static MMKV mmkvWithID(String mmapID) {
if (rootDir == null) {
throw new IllegalStateException("You should Call MMKV.initialize() first.");
}
verifyMMID(mmapID);

long handle = getMMKVWithID(mmapID, SINGLE_PROCESS_MODE, null);
return new MMKV(handle);
Expand All @@ -69,6 +70,7 @@ public static MMKV mmkvWithID(String mmapID, int mode) {
if (rootDir == null) {
throw new IllegalStateException("You should Call MMKV.initialize() first.");
}
verifyMMID(mmapID);

long handle = getMMKVWithID(mmapID, mode, null);
return new MMKV(handle);
Expand All @@ -79,6 +81,7 @@ public static MMKV mmkvWithID(String mmapID, int mode, String cryptKey) {
if (rootDir == null) {
throw new IllegalStateException("You should Call MMKV.initialize() first.");
}
verifyMMID(mmapID);

long handle = getMMKVWithID(mmapID, mode, cryptKey);
return new MMKV(handle);
Expand All @@ -92,6 +95,7 @@ public static MMKV mmkvWithID(String mmapID, int mode, String cryptKey) {
if (rootDir == null) {
throw new IllegalStateException("You should Call MMKV.initialize() first.");
}
verifyMMID(mmapID);

String processName =
MMKVContentProvider.getProcessNameByPID(context, android.os.Process.myPid());
Expand Down Expand Up @@ -137,6 +141,12 @@ public static MMKV mmkvWithID(String mmapID, int mode, String cryptKey) {
return null;
}

private static void verifyMMID(String mmapID) {
if (mmapID.indexOf('/') >= 0) {
throw new IllegalArgumentException("\"/\" is not allowed inside mmapID");
}
}

public static MMKV defaultMMKV() {
if (rootDir == null) {
throw new IllegalStateException("You should Call MMKV.initialize() first.");
Expand Down
2 changes: 1 addition & 1 deletion Android/MMKV/mmkvdemo/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ dependencies {
// implementation project(':mmkv')
implementation 'com.tencent:mmkv:1.0.10'
// implementation 'com.tencent:mmkv:1.0.10-SNAPSHOT'
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
Expand Down

0 comments on commit 9c75909

Please sign in to comment.