You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Maarten Boekhold (JIRA)" <ji...@apache.org> on 2015/10/03 16:10:26 UTC

[jira] [Commented] (CONFIGURATION-613) MapConfiguration cannot handle property set to single \t or \n

    [ https://issues.apache.org/jira/browse/CONFIGURATION-613?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14942314#comment-14942314 ] 

Maarten Boekhold commented on CONFIGURATION-613:
------------------------------------------------

It occurred to me that MapConfiguration is probably trying to skip leading whitespace, and a new test seems to confirm this:

{code}
@Grab(group='commons-configuration', module='commons-configuration', version='1.9')
import org.apache.commons.configuration.MapConfiguration
import org.apache.commons.configuration.PropertiesConfiguration

// groovy dollar-slashy-string syntax, ignores backslash
// as an escape character so \t remains a literal string
// backslash + t
def propsString = $/
prefix.field3=\tabc
/$

Properties props = new Properties()
props.load(new StringReader(propsString))
// OK
assert props.getProperty('prefix.field3') == '\tabc'

// MapConfiguration does not work
MapConfiguration mapcfg = new MapConfiguration(props)
// But should not be!
assert mapcfg.getString('prefix.field3') == 'abc'
// FAIL
// MapConfiguration loses the single tab character
assert mapcfg.getString('prefix.field3') == '\tabc'
{code}

with output

{noformat}
Exception thrown

Assertion failed: 

assert mapcfg.getString('prefix.field3') == '\tabc'
       |      |                          |
       |      abc                        false
       org.apache.commons.configuration.MapConfiguration@64cdc026


	at ConsoleScript2.run(ConsoleScript2:23)
{noformat}

As you can see from the following assert statement:

{code}
assert mapcfg.getString('prefix.field3') == 'abc'
{code}

The MapConfiguration seems to think that "prefix.field3" should be "abc" without a leading tab character. That's not how java.util.Properties interprets this: that one keeps the leading tab character **if it is specified as \t**.

In any case, **why** would MapConfiguration try to remove leading whitespace when it is initialized from a Properties instance? The Properties class would already have taken care of all of that presumably.


> MapConfiguration cannot handle property set to single \t or \n
> --------------------------------------------------------------
>
>                 Key: CONFIGURATION-613
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-613
>             Project: Commons Configuration
>          Issue Type: Bug
>            Reporter: Maarten Boekhold
>
> See the following test, written in groovy (2.4.4). Open a groovyConsole, copy/paste in this code and hit ctrl-Enter to run. You need a working internet connection.
> {code}
> @Grab(group='commons-configuration', module='commons-configuration', version='1.9')
> import org.apache.commons.configuration.MapConfiguration
> import org.apache.commons.configuration.PropertiesConfiguration
> // groovy dollar-slashy-string syntax, ignores backslash
> // as an escape character so \t remains a literal string
> // backslash + t
> def propsString = $/
> prefix.field1=\t
> prefix.field2=a\tb
> /$
> // Java properties work
> Properties props = new Properties()
> props.load(new StringReader(propsString))
> // OK
> assert props.getProperty('prefix.field1') == '\t'
> // OK
> assert props.getProperty('prefix.field2') == 'a\tb'
> // PropertiesConfiguration works
> PropertiesConfiguration propscfg = new PropertiesConfiguration()
> propscfg.load(new StringReader(propsString))
> // OK
> assert propscfg.getString('prefix.field1') == '\t'
> // OK
> assert propscfg.getProperty('prefix.field2') == 'a\tb'
> // MapConfiguration does not work
> MapConfiguration mapcfg = new MapConfiguration(props)
> // OK
> assert mapcfg.getProperty('prefix.field2') == 'a\tb'
> // FAIL
> // MapConfiguration loses the single tab character
> assert mapcfg.getString('prefix.field1') == '\t'
> {code}
> Output is:
> {noformat}
> Exception thrown
> Assertion failed: 
> assert mapcfg.getString('prefix.field1') == '\t'
>        |      |                          |
>        |      ""                         false
>        org.apache.commons.configuration.MapConfiguration@1cd4064c
> 	at ConsoleScript13.run(ConsoleScript13:35)
> {noformat}
> As you can see, once we've 'converted' the java.util.Properties instance to a MapConfiguration, the single \t character is lost. *Embedded* tab characters however are retained!



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)