You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Duncan Jones (JIRA)" <ji...@apache.org> on 2014/01/29 20:12:09 UTC
[jira] [Commented] (LANG-948) Exception while using
ExtendedMessageFormat and escaping braces
[ https://issues.apache.org/jira/browse/LANG-948?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13885667#comment-13885667 ]
Duncan Jones commented on LANG-948:
-----------------------------------
I think the problem lies with the {{appendQuotedString}} method, however I'm struggling to fix it because I'm not 100% sure what that method should be doing.
I propose that we make that method static and package-private, so we can unit test it in isolation. (It probably should be static anyway, as it uses no instance fields). My confusion is about the desired effect of the {{escapingOn}} attribute. I'm assuming that when it's {{true}}, two single quotes next to each other are treated as an escaped single quote, and the resulting string pushed onto the buffer should have un-escaped quotes. Conversely, when it's {{false}}, two singles quotes are treated as a quoted string of zero length.
>From these assumptions, I've created this little unit test:
{code:java}
@Test
public void testAppendQuotedString() throws Exception {
assertEquals("'test'", readFirstQuotedString("''test''123", true));
assertEquals("'test'", readFirstQuotedString("'test'123", true));
assertEquals("", readFirstQuotedString("''test''123", false));
}
private static String readFirstQuotedString(String input, boolean escapingOn) {
StringBuilder builder = new StringBuilder();
ExtendedMessageFormat.appendQuotedString(input, new ParsePosition(0), builder, escapingOn);
return builder.toString();
}
{code}
Note: these tests currently fail.
If someone can confirm (or correct) my understanding, I can fix the method and hopefully this bug.
> Exception while using ExtendedMessageFormat and escaping braces
> ---------------------------------------------------------------
>
> Key: LANG-948
> URL: https://issues.apache.org/jira/browse/LANG-948
> Project: Commons Lang
> Issue Type: Bug
> Components: lang.text.*
> Affects Versions: 3.2, 3.2.1
> Reporter: Nicolò Chieffo
> Fix For: Patch Needed
>
> Attachments: TestExtendedMessageFormat.java, TestExtendedMessageFormat2.java
>
>
> Exception while trying to format a string containing escaped braces
> {code}
> Exception in thread "main" java.lang.IllegalArgumentException: Invalid format argument index at position 7: }
> at org.apache.commons.lang3.text.ExtendedMessageFormat.readArgumentIndex(ExtendedMessageFormat.java:357)
> at org.apache.commons.lang3.text.ExtendedMessageFormat.applyPattern(ExtendedMessageFormat.java:167)
> at org.apache.commons.lang3.text.ExtendedMessageFormat.<init>(ExtendedMessageFormat.java:128)
> at org.apache.commons.lang3.text.ExtendedMessageFormat.<init>(ExtendedMessageFormat.java:113)
> at test.TestExtendedMessageFormat.main(TestExtendedMessageFormat.java:16)
> {code}
> I will attach a source
--
This message was sent by Atlassian JIRA
(v6.1.5#6160)