summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNarayan Kamath <narayan@google.com>2015-02-18 15:44:01 +0000
committerNarayan Kamath <narayan@google.com>2015-02-18 15:44:01 +0000
commit0f702b5996488b8cc8cbe336e8098dd1b4de8dd3 (patch)
tree9d58e4d199209a3b02f1a31a6bae7aeddf2d9517
parent76f9f6402ffb9fd069f494d16a61b8652ec85c81 (diff)
downloadlibcore-0f702b5996488b8cc8cbe336e8098dd1b4de8dd3.zip
libcore-0f702b5996488b8cc8cbe336e8098dd1b4de8dd3.tar.gz
libcore-0f702b5996488b8cc8cbe336e8098dd1b4de8dd3.tar.bz2
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
-rw-r--r--harmony-tests/src/test/java/org/apache/harmony/tests/java/text/MessageFormatTest.java8
-rw-r--r--luni/src/main/java/java/text/MessageFormat.java6
2 files changed, 14 insertions, 0 deletions
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 @@ public class MessageFormatTest extends TestCase {
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 @@ public class MessageFormat extends Format {
}
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);