From 886fc6348b1ea41b3c51d0875dc4915b9042132d Mon Sep 17 00:00:00 2001 From: Aleksey Pesternikov Date: Wed, 19 Jun 2019 07:13:41 -0700 Subject: [PATCH] backslashes must be escaped on write --- properties.go | 2 ++ properties_test.go | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/properties.go b/properties.go index cb3d1a3..0b0c182 100644 --- a/properties.go +++ b/properties.go @@ -820,6 +820,8 @@ func escape(r rune, special string) string { return "\\r" case '\t': return "\\t" + case '\\': + return "\\\\" default: if strings.ContainsRune(special, r) { return "\\" + string(r) diff --git a/properties_test.go b/properties_test.go index 5db64c3..f208df9 100644 --- a/properties_test.go +++ b/properties_test.go @@ -151,12 +151,14 @@ var writeTests = []struct { {"key = value \\\n continued", "key = value continued\n", "ISO-8859-1"}, {"key⌘ = value", "key\\u2318 = value\n", "ISO-8859-1"}, {"ke\\ \\:y = value", "ke\\ \\:y = value\n", "ISO-8859-1"}, + {"ke\\\\y = val\\\\ue", "ke\\\\y = val\\\\ue\n", "ISO-8859-1"}, // UTF-8 tests {"key = value", "key = value\n", "UTF-8"}, {"key = value \\\n continued", "key = value continued\n", "UTF-8"}, {"key⌘ = value⌘", "key⌘ = value⌘\n", "UTF-8"}, {"ke\\ \\:y = value", "ke\\ \\:y = value\n", "UTF-8"}, + {"ke\\\\y = val\\\\ue", "ke\\\\y = val\\\\ue\n", "UTF-8"}, } // ---------------------------------------------------------------------------- @@ -329,6 +331,7 @@ var stringTests = []struct { }{ // valid values {"key = abc", "key", "def", "abc"}, + {"key = ab\\\\c", "key", "def", "ab\\c"}, // non existent key {"key = abc", "key2", "def", "def"}, @@ -345,6 +348,7 @@ var keysTests = []struct { {"key = abc\nkey2=def", []string{"key", "key2"}}, {"key2 = abc\nkey=def", []string{"key2", "key"}}, {"key = abc\nkey=def", []string{"key"}}, + {"key\\\\with\\\\backslashes = abc", []string{"key\\with\\backslashes"}}, } // ----------------------------------------------------------------------------