commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Maarten Boekhold (JIRA)" <>
Subject [jira] [Created] (CONFIGURATION-613) MapConfiguration cannot handle property set to single \t or \n
Date Fri, 02 Oct 2015 10:51:27 GMT
Maarten Boekhold created CONFIGURATION-613:

             Summary: MapConfiguration cannot handle property set to single \t or \n
                 Key: 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.

@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 = $/

// 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'
// MapConfiguration loses the single tab character
assert mapcfg.getString('prefix.field1') == '\t'

Output is:

Exception thrown

Assertion failed: 

assert mapcfg.getString('prefix.field1') == '\t'
       |      |                          |
       |      ""                         false


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

View raw message