You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Ats (JIRA)" <ji...@apache.org> on 2013/04/06 19:41:16 UTC

[jira] [Comment Edited] (CONFIGURATION-538) Saving PropertiesConfiguration using UTF-8 encoding doesn't work

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

Ats edited comment on CONFIGURATION-538 at 4/6/13 5:40 PM:
-----------------------------------------------------------

Nice, that workaround for this issue can be done with less effort.

> So if I understand correctly, the problem currently is that an escaping is manually performed when saving properties which is not necessarily compatible with the specified encoding, right?
I wouldn't phrase it exactly this way. Instead of "escaping is manually performed" i'd say that escaping is automatically performed even for UTF-8 characters that can be expressed without escaping. I would say that this is unexpected behavior as if you store java.util.Properties to file like that:
      fos = new FileOutputStream(tmpPropsFile);
      w = new OutputStreamWriter(fos, "UTF-8");
      properties.store(w, null);
then such escaping is not done. 

I would expect that PropertiesConfiguration would behave similarly in following scenario:
    PropertiesConfiguration c = new PropertiesConfiguration();
    c.setProperty("testKey", "example UTF-8 chars are š õ ä ö ü ž");
    c.setEncoding("UTF-8");
    c.save(tmpPropsFile);

and/or in following scenario:
      fos = new FileOutputStream(tmpPropsFile);
      c.save(fos, "UTF-8");

                
      was (Author: atsu85):
    Nice, that workaround for this issue can be done with less effort.

> So if I understand correctly, the problem currently is that an escaping is manually performed when saving properties which is not necessarily compatible with the specified encoding, right?
I wouldn't phrase it exactly this way. Instead of "escaping is manually performed" i'd say that escaping is automatically performed even for UTF-8 characters that can be expressed without escaping. I would say that this is unexpected behavior as if you store java.util.Properties to file like that:
      fos = new FileOutputStream(tmpPropsFile);
      w = new OutputStreamWriter(fos, "UTF-8");
      properties.store(w, null);
then such escaping is not done. I would expect that PropertiesConfiguration would behave similarly in following scenario:
    PropertiesConfiguration c = new PropertiesConfiguration();
    c.setProperty("testKey", "example UTF-8 chars are š õ ä ö ü ž");
    c.setEncoding("UTF-8");
    c.save(tmpPropsFile);
and/or in following scenario:
      fos = new FileOutputStream(tmpPropsFile);
      c.save(fos, "UTF-8");

                  
> Saving PropertiesConfiguration using UTF-8 encoding doesn't work
> ----------------------------------------------------------------
>
>                 Key: CONFIGURATION-538
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-538
>             Project: Commons Configuration
>          Issue Type: Bug
>    Affects Versions: 1.9
>         Environment: shouldn't be important, but 64bit Windows 7
>            Reporter: Ats
>              Labels: PropertiesConfiguration,, charset, encoding,, save
>
> I created JUnit test http://goo.gl/GCwi2, that uses two methods to save PropertiesConfiguration (with property value containing utf-8 characters) into file:
> 1) propsConf.save(file); // propsConf.setEncoding("UTF-8") was called before
> and
> 2) propsConf.save(fileOutputStream, "UTF-8");
> Test shows that file doesn't contain UTF-8 characters. Instead saved file contains unicode escapes of non ISO-8859-1 characters.
> This seems wrong, as documentation on setEncoding() method says:
> "Set the encoding used to store the configuration file".
> PropertiesConfiguration.setEncoding() method currently seems to affect only loading the configuration.
> I added one test method that shows that even java.util.Properties class saves the same property value without any problems using utf-8 characters (not unicode escapes that it ) when using smth like that:
> props.store(new OutputStreamWriter(fos, "UTF-8"));
> It looks like a bug to me, or did i misunderstood smth?

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira