Repository: commons-text Updated Branches: refs/heads/master ee6017fcb -> b647f0496
TEXT-106: Exception thrown in ExtendedMessageFormat using quotes with custom registry Applying patch provided by Benoît Moreau (thanks!). Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/1596501e Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/1596501e Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/1596501e Branch: refs/heads/master Commit: 1596501e610bca7955969bb94fe6c6bad397e361 Parents: e55d0ac Author: Bruno P. Kinoshita <brunodepau...@yahoo.com.br> Authored: Sun Oct 29 00:28:04 2017 +1300 Committer: Bruno P. Kinoshita <brunodepau...@yahoo.com.br> Committed: Sun Oct 29 00:28:04 2017 +1300 ---------------------------------------------------------------------- src/changes/changes.xml | 1 + .../org/apache/commons/text/ExtendedMessageFormat.java | 5 ++++- .../apache/commons/text/ExtendedMessageFormatTest.java | 11 +++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-text/blob/1596501e/src/changes/changes.xml ---------------------------------------------------------------------- diff --git a/src/changes/changes.xml b/src/changes/changes.xml index e43bd8f..ec57b1f 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -46,6 +46,7 @@ The <action> type attribute can be add,update,fix,remove. <body> <release version="1.2" date="2017-MM-DD" description="Release 1.2"> + <action issue="TEXT-106" type="fix" dev="kinow" due-to="Benoit Moreau">Exception thrown in ExtendedMessageFormat using quotes with custom registry</action> <action issue="TEXT-100" type="fix" dev="kinow" due-to="Don Jeba">StringEscapeUtils#UnEscapeJson doesn't recognize escape signs correctly</action> <action issue="TEXT-74" type="add" dev="chtompki" due-to="Ioannis Sermetziadis">StrSubstitutor: Ability to turn off substitution in values</action> <action issue="TEXT-97" type="add" dev="chtompki" due-to="Amey Jadiye">RandomStringGenerator able to pass multiple ranges to .withinRange()</action> http://git-wip-us.apache.org/repos/asf/commons-text/blob/1596501e/src/main/java/org/apache/commons/text/ExtendedMessageFormat.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/text/ExtendedMessageFormat.java b/src/main/java/org/apache/commons/text/ExtendedMessageFormat.java index dcf0766..cfe1bf4 100644 --- a/src/main/java/org/apache/commons/text/ExtendedMessageFormat.java +++ b/src/main/java/org/apache/commons/text/ExtendedMessageFormat.java @@ -411,21 +411,24 @@ public class ExtendedMessageFormat extends MessageFormat { seekNonWs(pattern, pos); final int text = pos.getIndex(); int depth = 1; - for (; pos.getIndex() < pattern.length(); next(pos)) { + while (pos.getIndex() < pattern.length()) { switch (pattern.charAt(pos.getIndex())) { case START_FE: depth++; + next(pos); break; case END_FE: depth--; if (depth == 0) { return pattern.substring(text, pos.getIndex()); } + next(pos); break; case QUOTE: getQuotedString(pattern, pos); break; default: + next(pos); break; } } http://git-wip-us.apache.org/repos/asf/commons-text/blob/1596501e/src/test/java/org/apache/commons/text/ExtendedMessageFormatTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/text/ExtendedMessageFormatTest.java b/src/test/java/org/apache/commons/text/ExtendedMessageFormatTest.java index 640b5b0..7e32236 100644 --- a/src/test/java/org/apache/commons/text/ExtendedMessageFormatTest.java +++ b/src/test/java/org/apache/commons/text/ExtendedMessageFormatTest.java @@ -102,6 +102,17 @@ public class ExtendedMessageFormatTest { } /** + * Test Bug TEXT-106 - Exception while using ExtendedMessageFormat and choice format element with quote just before brace end + */ + @Test + public void testChoiceQuoteJustBeforeBraceEnd_TEXT_106() { + final String pattern2 = "Message with choice format element with quote just before brace end ''{0,choice,0#0|0<'1'}''"; + final ExtendedMessageFormat emf = new ExtendedMessageFormat(pattern2, registry); + assertEquals("Message with choice format element with quote just before brace end '0'", emf.format(new Object[] {0})); + assertEquals("Message with choice format element with quote just before brace end '1'", emf.format(new Object[] {1})); + } + + /** * Test extended and built in formats. */ @Test