Add option to not escape # ! = : characters in values
Given this small program (running on Python 2.7) using jprops 2.0.2:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import io
import jprops
content = {"key": '<a href="http://example.com/#anchor">link!</a>'}
with io.open("out.properties", mode='w') as message_file:
jprops.store_properties(message_file, content)
It will create a file called "out.properties" with the following content:
#Wed Apr 26 14:14:47 CEST 2017
key=<a href\="http\://example.com/\#anchor">link\!</a>
There is no need to escape the "comment characters" or "key terminators" in values. When creating a similar file with Java, it does not escape them.
FYI: When talking about keys, Java only seems to escape # or ! when it is the first character. jprops always escapes them.
Thanks for reporting this. I looked back at the Java docs which say:
The key and element characters #, !, =, and : are written with a preceding backslash to ensure that they are properly loaded.
So, the docs seem to claim that it's more conservative and always escapes those, which is what I based that on. I guess they changed the implementation to reduce escaping in places that would still parse unambiguously.
Since this still produces a valid output, and I have a few other things going on I may not get to it right away. Would you be interested in submitting a PR?
The key and element characters #, !, =, and : are written with a preceding backslash to ensure that they are properly loaded.
So, the docs seem to claim that it's more conservative and always escapes those, which is what I based that on.
Hmm, you are right. I have written a small Java test case and it actually follows that (and jprops') behaviour.
I must have confused it with IntelliJ's behaviour (which is not escaping those characters) and thought it was supposed to work like that.
So... we can keep jprops' current behaviour. Maybe the store_properties method could have an optional "more human readable" boolean parameter that controls how it will escape keys/values? But you can consider this a very low priority feature request.
Maybe one day I will find the time to actually create a PR for it...
Ah ok, thanks for investigating more. Yeah, if that is the standard behavior for Java I will stick to that as the default, but I'll leave this open for now to possibly add an option to minimize escaping.