jnbt / java-properties

Loader and writer for *.properties files
MIT License
42 stars 22 forks source link

Backslash is not unescaped #13

Closed vibin closed 4 years ago

vibin commented 4 years ago

For hello=wo\\d, the API JavaProperties.load("sample.properties")['hello'.to_sym] returns wo\\d instead of wo\d.

vibin commented 4 years ago

TBF, I'm not sure if this is a bug (i'm new to ruby), but the JDK Properties API definitely does unescape backslashes.

jnbt commented 4 years ago

This is in fact an interesting behavior. I checked the Java behavior and you' right, a property with a back\\slash value will be parsed to back\slash.

Obviously this is important for situations with escaped special chars, e.g. back\\tslash where the sequence should not contain a tabulator.

jnbt commented 4 years ago

@vibin I added a fix for this behavior. Can you test the new version? If you use this gem via a Bundler you can simply use the following line to your Gemfile load the unpublished version:

gem 'java-properties', github: 'jnbt/java-properties', branch: 'fix-backslash-not-unescaped'

and then run bundle install

vibin commented 4 years ago

@jnbt this fixes the issue. Thank you!

jnbt commented 4 years ago

@vibin Thanks for your feedback. The fix has been released as version 0.2.1: https://rubygems.org/gems/java-properties/versions/0.2.1