From bc00cce9bd07689346a8c5b03a61c5b91c60adef Mon Sep 17 00:00:00 2001 From: Connor Tumbleson Date: Tue, 19 Sep 2017 17:02:42 -0400 Subject: [PATCH] Add support for 4 non-positional attributes - adds tests - fixes #1611 --- .../java/brut/androlib/res/xml/ResXmlEncoders.java | 4 ++-- .../java/brut/androlib/PositionalEnumerationTest.java | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/xml/ResXmlEncoders.java b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/xml/ResXmlEncoders.java index e43cb8870b..d45434ceed 100644 --- a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/xml/ResXmlEncoders.java +++ b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/xml/ResXmlEncoders.java @@ -143,12 +143,12 @@ public static String encodeAsXmlValue(String str) { } public static boolean hasMultipleNonPositionalSubstitutions(String str) { - Duo, List> tuple = findSubstitutions(str, 3); + Duo, List> tuple = findSubstitutions(str, 4); return ! tuple.m1.isEmpty() && tuple.m1.size() + tuple.m2.size() > 1; } public static String enumerateNonPositionalSubstitutionsIfRequired(String str) { - Duo, List> tuple = findSubstitutions(str, 3); + Duo, List> tuple = findSubstitutions(str, 4); if (tuple.m1.isEmpty() || tuple.m1.size() + tuple.m2.size() < 2) { return str; } diff --git a/brut.apktool/apktool-lib/src/test/java/brut/androlib/PositionalEnumerationTest.java b/brut.apktool/apktool-lib/src/test/java/brut/androlib/PositionalEnumerationTest.java index 18a5254699..eb2f3d969a 100644 --- a/brut.apktool/apktool-lib/src/test/java/brut/androlib/PositionalEnumerationTest.java +++ b/brut.apktool/apktool-lib/src/test/java/brut/androlib/PositionalEnumerationTest.java @@ -51,6 +51,16 @@ public void threePositionalArgumentsTest() { assertEquals(" %1$s, %2$s and %3$d other", enumerateArguments(" %1$s, %2$s and %3$d other")); } + @Test + public void fourArgumentsTest() { + assertEquals("%1$s, %2$s, and %3$d other and %4$d.", enumerateArguments("%s, %s, and %d other and %d.")); + } + + @Test + public void fourPositionalArgumentsTest() { + assertEquals(" %1$s, %2$s and %3$d other and %4$d.", enumerateArguments(" %1$s, %2$s and %3$d other and %4$d.")); + } + private String enumerateArguments(String value) { return ResXmlEncoders.enumerateNonPositionalSubstitutionsIfRequired(value); }