Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/cfpropertylist/rbCFTypes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def to_binary(bplist)
end

def to_plain(plist)
if @value =~ /^\w+$/
if @value =~ /\A\w+\z/
@value
else
quoted
Expand All @@ -74,15 +74,15 @@ def quoted
when '"'
'\\"'
when '\\'
'\\'
'\\\\'
when "\a"
"\\a"
when "\b"
"\\b"
when "\f"
"\\f"
when "\n"
"\n"
"\\n"
when "\v"
"\\v"
when "\r"
Expand Down
24 changes: 24 additions & 0 deletions test/test_plain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,28 @@ def test_serialize
plist.value = CFPropertyList.guess(CFPropertyList::Blob.new("\x00\n"))
assert_equal raw_plain("binary"), plist.to_str(CFPropertyList::List::FORMAT_PLAIN)
end

def test_string_with_backslash_roundtrip
original = "foo\\bar"
plist = CFPropertyList::List.new
plist.value = CFPropertyList.guess(original)
plain = plist.to_str(CFPropertyList::List::FORMAT_PLAIN)

reparsed = CFPropertyList::List.new(:data => plain, :format => CFPropertyList::List::FORMAT_PLAIN)
result = CFPropertyList.native_types(reparsed.value)

assert_equal original, result
end

def test_string_with_newline_roundtrip
original = "foo\nbar"
plist = CFPropertyList::List.new
plist.value = CFPropertyList.guess(original)
plain = plist.to_str(CFPropertyList::List::FORMAT_PLAIN)

reparsed = CFPropertyList::List.new(:data => plain, :format => CFPropertyList::List::FORMAT_PLAIN)
result = CFPropertyList.native_types(reparsed.value)

assert_equal original, result
end
end