mirror of
https://github.com/keymanapp/keyman.git
synced 2026-10-11 00:17:28 +00:00
fix(android): Prevent lower-cased API returns from causing mismatches
Cherrypick of #2404 to master Note: Keyman 12.0 uses `CloudRepository` which is refactored in 13.0 to `CloudDataJsonUtil`. The unit test is adjusted accordingly.
This commit is contained in:
parent
9f52b12a9d
commit
63d64ae569
8 changed files with 130 additions and 6 deletions
|
|
@ -356,7 +356,7 @@ public class CloudRepository {
|
|||
}
|
||||
}
|
||||
|
||||
protected List<Keyboard> processKeyboardJSON(JSONObject query, boolean fromKMP) {
|
||||
protected static List<Keyboard> processKeyboardJSON(JSONObject query, boolean fromKMP) {
|
||||
List<Keyboard> keyboardsList = new ArrayList<>();
|
||||
if (query.length() == 0) {
|
||||
return keyboardsList;
|
||||
|
|
@ -389,7 +389,7 @@ public class CloudRepository {
|
|||
hashMap.put(KMManager.KMKey_PackageID, pkgID);
|
||||
hashMap.put(KMManager.KMKey_KeyboardID, kbID);
|
||||
hashMap.put(KMManager.KMKey_LanguageName, langName);
|
||||
hashMap.put(KMManager.KMKey_LanguageID, langID);
|
||||
hashMap.put(KMManager.KMKey_LanguageID, langID.toLowerCase());
|
||||
hashMap.put(KMManager.KMKey_KeyboardVersion, kbVersion);
|
||||
hashMap.put(KMManager.KMKey_CustomKeyboard, isCustom);
|
||||
hashMap.put(KMManager.KMKey_Font, kbFont);
|
||||
|
|
@ -409,7 +409,7 @@ public class CloudRepository {
|
|||
return keyboardsList;
|
||||
}
|
||||
|
||||
protected List<LexicalModel> processLexicalModelJSON(JSONArray models) {
|
||||
protected static List<LexicalModel> processLexicalModelJSON(JSONArray models) {
|
||||
List<LexicalModel> modelList = new ArrayList<>(models.length());
|
||||
|
||||
try {
|
||||
|
|
@ -451,7 +451,7 @@ public class CloudRepository {
|
|||
|
||||
HashMap<String, String> hashMap = new HashMap<String, String>();
|
||||
hashMap.put(KMManager.KMKey_PackageID, packageID);
|
||||
hashMap.put(KMManager.KMKey_LanguageID, languageID);
|
||||
hashMap.put(KMManager.KMKey_LanguageID, languageID.toLowerCase());
|
||||
hashMap.put(KMManager.KMKey_LexicalModelID, modelID);
|
||||
hashMap.put(KMManager.KMKey_LexicalModelName, modelName);
|
||||
hashMap.put(KMManager.KMKey_LanguageName, langName);
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ public class LexicalModelPackageProcessor extends PackageProcessor {
|
|||
models[i].put(KMManager.KMKey_LexicalModelID, jsonEntry.getString("id"));
|
||||
// Use package version for the lexical model version
|
||||
models[i].put(KMManager.KMKey_LexicalModelVersion, packageVersion);
|
||||
models[i].put(KMManager.KMKey_LanguageID, languages.getJSONObject(i).getString("id"));
|
||||
models[i].put(KMManager.KMKey_LanguageID, languages.getJSONObject(i).getString("id").toLowerCase());
|
||||
models[i].put(KMManager.KMKey_LanguageName, languages.getJSONObject(i).getString("name"));
|
||||
|
||||
if (welcomeExists(packageId)) {
|
||||
|
|
|
|||
|
|
@ -156,7 +156,7 @@ public class PackageProcessor {
|
|||
keyboards[i].put(KMManager.KMKey_PackageID, packageId);
|
||||
keyboards[i].put(KMManager.KMKey_KeyboardName, jsonEntry.getString("name"));
|
||||
keyboards[i].put(KMManager.KMKey_KeyboardID, jsonEntry.getString("id"));
|
||||
keyboards[i].put(KMManager.KMKey_LanguageID, languages.getJSONObject(i).getString("id"));
|
||||
keyboards[i].put(KMManager.KMKey_LanguageID, languages.getJSONObject(i).getString("id").toLowerCase());
|
||||
keyboards[i].put(KMManager.KMKey_LanguageName, languages.getJSONObject(i).getString("name"));
|
||||
keyboards[i].put(KMManager.KMKey_KeyboardVersion, jsonEntry.getString("version"));
|
||||
if (jsonEntry.has("displayFont")) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,62 @@
|
|||
package com.tavultesoft.kmea.data;
|
||||
|
||||
import com.tavultesoft.kmea.JSONParser;
|
||||
import com.tavultesoft.kmea.KMManager;
|
||||
import com.tavultesoft.kmea.data.LexicalModel;
|
||||
import com.tavultesoft.kmea.packages.JSONUtils;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
// In Keyman 13.0, this becomes CloudDataJsonUtilTest
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class CloudRepositoryTest {
|
||||
private static final File TEST_RESOURCE_ROOT = new File("test_resources", "cloud");
|
||||
private static final String TAG = "CloudDataJsonUtilTest";
|
||||
|
||||
private final String pkgID = "sil_cameroon_qwerty";
|
||||
private final String langID = "bag-Latn";
|
||||
private final String langName = "Tuki (Latin)";
|
||||
private final String keyboardID = "sil_cameroon_qwerty";
|
||||
private final String keyboardName = "Cameroon QWERTY";
|
||||
private final String keyboardVersion = "6.0.1";
|
||||
private final String customKeyboard = "N";
|
||||
private final String aFont = "AndikaAfr";
|
||||
private final String oskFont = aFont;
|
||||
|
||||
@Before
|
||||
public void initializeTestPackage() {
|
||||
JSONUtils.initialize(TEST_RESOURCE_ROOT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldLowercaseLanguageID() {
|
||||
JSONParser parser = new JSONParser();
|
||||
|
||||
// Test processKeyboardJSON()
|
||||
JSONObject query = parser.getJSONObjectFromFile(new File(TEST_RESOURCE_ROOT, "bag-Latn.json"));
|
||||
List<Keyboard> keyboardResults = CloudRepository.processKeyboardJSON(query, false);
|
||||
Keyboard kbInfo = keyboardResults.get(0);
|
||||
Assert.assertEquals("bag-latn", kbInfo.getLanguageCode());
|
||||
|
||||
// Test processLexicalModelJSON()
|
||||
query = parser.getJSONObjectFromFile(new File(TEST_RESOURCE_ROOT, "sencoten.json"));
|
||||
JSONArray cloud = new JSONArray();
|
||||
cloud.put(query);
|
||||
List<LexicalModel> results = CloudRepository.processLexicalModelJSON(cloud);
|
||||
|
||||
LexicalModel lmInfo = results.get(0);
|
||||
Assert.assertEquals("str-latn", lmInfo.getLanguageCode());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -79,6 +79,7 @@ public class LexicalModelPackageProcessorTest {
|
|||
Assert.assertEquals(en_custom, models[0]);
|
||||
|
||||
// Lexical model same, but different language pairing
|
||||
// Verifies en-US from kmp.json gets lower-cased
|
||||
en_custom.put(KMManager.KMKey_LanguageID, "en-us");
|
||||
en_custom.put(KMManager.KMKey_LanguageName, "English (US)");
|
||||
|
||||
|
|
|
|||
39
android/KMEA/test_resources/cloud/bag-Latn.json
Normal file
39
android/KMEA/test_resources/cloud/bag-Latn.json
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
{
|
||||
"options": {
|
||||
"context": "language",
|
||||
"dateFormat": "standard",
|
||||
"device": "androidphone",
|
||||
"keyboardBaseUri": "https://s.keyman.com/keyboard/",
|
||||
"fontBaseUri": "https://s.keyman.com/font/deploy/",
|
||||
"keyboardVersion": "current"
|
||||
},
|
||||
"languages": {
|
||||
"languages": [
|
||||
{
|
||||
"name": "Tuki (Latin)",
|
||||
"id": "bag-latn",
|
||||
"region": 2,
|
||||
"keyboards": [
|
||||
{
|
||||
"id": "sil_cameroon_azerty",
|
||||
"name": "Cameroon AZERTY",
|
||||
"filename": "sil_cameroon_azerty/6.0/sil_cameroon_azerty-6.0.js",
|
||||
"version": "6.0",
|
||||
"source": "https://github.com/keymanapp/keyboards/tree/master/release/sil/sil_cameroon_azerty",
|
||||
"lastModified": "2019-11-28",
|
||||
"fileSize": 55534
|
||||
},
|
||||
{
|
||||
"id": "sil_cameroon_qwerty",
|
||||
"name": "Cameroon QWERTY",
|
||||
"filename": "sil_cameroon_qwerty/6.0.1/sil_cameroon_qwerty-6.0.1.js",
|
||||
"version": "6.0.1",
|
||||
"source": "https://github.com/keymanapp/keyboards/tree/master/release/sil/sil_cameroon_qwerty",
|
||||
"lastModified": "2019-11-28",
|
||||
"fileSize": 55348
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
22
android/KMEA/test_resources/cloud/sencoten.json
Normal file
22
android/KMEA/test_resources/cloud/sencoten.json
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
|
||||
{
|
||||
"id": "nrc.str.sencoten",
|
||||
"name": "SEN\u0106O\u0166EN (Saanich Dialect) Lexical Model",
|
||||
"license": "mit",
|
||||
"version": "1.0.4",
|
||||
"languages": [
|
||||
"str-Latn"
|
||||
],
|
||||
"authorName": "Eddie Antonio Santos",
|
||||
"jsFileSize": 2116107,
|
||||
"jsFilename": "https://downloads.keyman.com/models/nrc.str.sencoten/1.0.4/nrc.str.sencoten.model.js",
|
||||
"sourcePath": "release/nrc/nrc.str.sencoten",
|
||||
"authorEmail": "Eddie.Santos@nrc-cnrc.gc.ca",
|
||||
"description": "SEN\u0106O\u0166EN (Saanich Dialect)",
|
||||
"packageFileSize": 257025,
|
||||
"packageFilename": "https://downloads.keyman.com/models/nrc.str.sencoten/1.0.4/nrc.str.sencoten.model.kmp",
|
||||
"packageIncludes": [],
|
||||
"lastModifiedDate": "2019-11-28T00:41:52.076Z",
|
||||
"minKeymanVersion": "12.0"
|
||||
}
|
||||
|
||||
Binary file not shown.
Loading…
Add table
Reference in a new issue