fix regression of lang qualifiers

- values-xx was improperly decoded as values-b+xx
 - added unit test
This commit is contained in:
Connor Tumbleson 2015-04-11 12:39:38 -05:00
parent 1bb8ec02b2
commit bb6cd98dfa
3 changed files with 19 additions and 8 deletions

View File

@ -74,8 +74,8 @@ public class ResConfigFlags {
smallestScreenWidthDp = 0; smallestScreenWidthDp = 0;
screenWidthDp = 0; screenWidthDp = 0;
screenHeightDp = 0; screenHeightDp = 0;
localeScript = new char[] { '\00', '\00', '\00', '\00' }; localeScript = null;
localeVariant = new char[] { '\00', '\00', '\00', '\00', '\00', '\00', '\00', '\00' }; localeVariant = null;
isInvalid = false; isInvalid = false;
mQualifiers = ""; mQualifiers = "";
} }
@ -114,7 +114,7 @@ public class ResConfigFlags {
isInvalid = true; isInvalid = true;
} }
if (localeScript.length != 0) { if (localeScript != null && localeScript.length != 0) {
if (localeScript[0] == '\00') { if (localeScript[0] == '\00') {
localeScript = null; localeScript = null;
} }
@ -122,7 +122,7 @@ public class ResConfigFlags {
localeScript = null; localeScript = null;
} }
if (localeVariant.length != 0) { if (localeVariant != null && localeVariant.length != 0) {
if (localeVariant[0] == '\00') { if (localeVariant[0] == '\00') {
localeVariant = null; localeVariant = null;
} }

View File

@ -292,11 +292,11 @@ public class ARSCDecoder {
screenHeightDp = mIn.readShort(); screenHeightDp = mIn.readShort();
} }
char[] localeScript = {'\00'}; char[] localeScript = null;
char[] localeVariant = {'\00'}; char[] localeVariant = null;
if (size >= 48) { if (size >= 48) {
localeScript = this.readScriptOrVariantChar(4).toCharArray(); localeScript = readScriptOrVariantChar(4).toCharArray();
localeVariant = this.readScriptOrVariantChar(8).toCharArray(); localeVariant = readScriptOrVariantChar(8).toCharArray();
} }
int exceedingSize = size - KNOWN_CONFIG_BYTES; int exceedingSize = size - KNOWN_CONFIG_BYTES;

View File

@ -207,6 +207,11 @@ public class BuildAndDecodeTest {
compareValuesFiles("values-ast/strings.xml"); compareValuesFiles("values-ast/strings.xml");
} }
@Test
public void twoLetterNotHandledAsBcpTest() throws BrutException, IOException {
checkFolderExists("res/values-fr");
}
@Test @Test
public void twoLetterLangBcp47Test() throws BrutException, IOException { public void twoLetterLangBcp47Test() throws BrutException, IOException {
compareValuesFiles("values-en-rUS/strings.xml"); compareValuesFiles("values-en-rUS/strings.xml");
@ -361,6 +366,12 @@ public class BuildAndDecodeTest {
compareXmlFiles(path, null); compareXmlFiles(path, null);
} }
private void checkFolderExists(String path) throws BrutException {
File f = new File(sTestNewDir, path);
assertTrue(f.isDirectory());
}
private void compareXmlFiles(String path, ElementQualifier qualifier) private void compareXmlFiles(String path, ElementQualifier qualifier)
throws BrutException { throws BrutException {
DetailedDiff diff; DetailedDiff diff;