Deal with quoted subformat patterns correctly.
This change might look like a hack, but the API it
implements is more than worthy of it.
bug: 19011159
Change-Id: I8a539f1b54282220fbb0a005a750819fa7873cc9
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/text/MessageFormatTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/text/MessageFormatTest.java
index 171f247..0920714 100644
--- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/text/MessageFormatTest.java
+++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/text/MessageFormatTest.java
@@ -950,4 +950,12 @@
String res = MessageFormat.format("bgcolor=\"{10}\"", messageArgs);
assertEquals(res, "bgcolor=\"example10\"");
}
+
+ // http://b/19011159
+ public void test19011159() {
+ final String pattern = "ab{0,choice,0#1'2''3'''4''''.}yz";
+ final MessageFormat format = new MessageFormat(pattern, Locale.ENGLISH);
+ final Object[] zero0 = new Object[] { 0 };
+ assertEquals("ab12'3'4''.yz", format.format(zero0));
+ }
}
diff --git a/luni/src/main/java/java/text/MessageFormat.java b/luni/src/main/java/java/text/MessageFormat.java
index cf306a7..f48cebd 100644
--- a/luni/src/main/java/java/text/MessageFormat.java
+++ b/luni/src/main/java/java/text/MessageFormat.java
@@ -580,6 +580,12 @@
}
if (format instanceof ChoiceFormat) {
String result = format.format(arg);
+ // Escape quotes in the result because the ChoiceFormat would've already
+ // dealt with them for us. In other words, any quotes that are present in the
+ // result are due to escaped quotes in the original input. We should preserve
+ // them in the output instead of having them processed again with the message
+ // format we're creating below.
+ result = result.replace("'", "''");
MessageFormat mf = new MessageFormat(result);
mf.setLocale(locale);
mf.format(objects, buffer, passedField);