mgood/jprops

Do not escape spaces in values

Closed this issue · 1 comments

Given this small program (running on Python 2.7):

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import io
import jprops

content = {"key": "foo bar"}
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:

#Fri Apr 21 10:44:05 CEST 2017
key=foo\ bar

There is no need to escape spaces in values. My editor (IntelliJ IDEA) is even complaining about "Invalid string escape". Note that you really have no choice for keys and there you need to escape spaces.

This might not be a big deal, but it hurts readability (for humans).

Oh, I think I found the cause. The write_property method contains this:

value = self._escape_key(value)

If you replace it by

value = self._escape_value(value)

then the output file seems to be fine.