Skip to content

Commit 3d981e4

Browse files
committed
po: add missing \r escape on output
1 parent 746e53a commit 3d981e4

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

lib/gettext/po_entry.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,11 +241,13 @@ class << self
241241
def escape(string)
242242
return "" if string.nil?
243243

244-
string.gsub(/([\\"\t\n])/) do
244+
string.gsub(/([\\"\t\r\n])/) do
245245
special_character = $1
246246
case special_character
247247
when "\t"
248248
"\\t"
249+
when "\r"
250+
"\\r"
249251
when "\n"
250252
"\\n"
251253
else

test/test_po_entry.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,13 +233,15 @@ def test_plural
233233
class TestEscape < self
234234
def test_normal
235235
entry = GetText::POEntry.new(:normal)
236-
entry.msgid = "He said \"hello.\""
237-
entry.msgstr = "Il a dit \"bonjour.\""
236+
entry.msgid = "He said \"hello.\"\r\n"
237+
entry.msgstr = "Il a dit \"bonjour.\"\r\n"
238238
entry.references = ["file1:1", "file2:10"]
239239
expected_po = <<-EOE
240240
#: file1:1 file2:10
241-
msgid "He said \\"hello.\\""
242-
msgstr "Il a dit \\"bonjour.\\""
241+
msgid ""
242+
"He said \\"hello.\\"\\r\\n"
243+
msgstr ""
244+
"Il a dit \\"bonjour.\\"\\r\\n"
243245
EOE
244246
assert_equal(expected_po, entry.to_s)
245247
end

0 commit comments

Comments
 (0)