commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Duncan Jones (JIRA)" <>
Subject [jira] [Commented] (LANG-948) Exception while using ExtendedMessageFormat and escaping braces
Date Wed, 29 Jan 2014 19:12:09 GMT


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:

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();

Note: these tests currently fail.

If someone can confirm (or correct) my understanding, I can fix the method and hopefully this

> Exception while using ExtendedMessageFormat and escaping braces
> ---------------------------------------------------------------
>                 Key: LANG-948
>                 URL:
>             Project: Commons Lang
>          Issue Type: Bug
>          Components: lang.text.*
>    Affects Versions: 3.2, 3.2.1
>            Reporter: Nicolò Chieffo
>             Fix For: Patch Needed
>         Attachments:,
> 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(
> 	at org.apache.commons.lang3.text.ExtendedMessageFormat.applyPattern(
> 	at org.apache.commons.lang3.text.ExtendedMessageFormat.<init>(
> 	at org.apache.commons.lang3.text.ExtendedMessageFormat.<init>(
> 	at test.TestExtendedMessageFormat.main(
> {code}
> I will attach a source

This message was sent by Atlassian JIRA

View raw message