diff --git a/lib/syntax_tree/node.rb b/lib/syntax_tree/node.rb index a2c78677..7b500c96 100644 --- a/lib/syntax_tree/node.rb +++ b/lib/syntax_tree/node.rb @@ -288,7 +288,8 @@ def format(q) q.text(value) else q.text(q.quote) - q.text(value[1] == "\"" ? "\\\"" : value[1]) + double_quotation = q.quote == "'" ? "\"" : "\\\"" + q.text(value[1] == "\"" ? double_quotation : value[1]) q.text(q.quote) end end diff --git a/test/plugin/single_quotes_test.rb b/test/plugin/single_quotes_test.rb index 6ce10448..81c210a2 100644 --- a/test/plugin/single_quotes_test.rb +++ b/test/plugin/single_quotes_test.rb @@ -8,6 +8,10 @@ def test_empty_string_literal assert_format("''\n", "\"\"") end + def test_character_literal + assert_format("'\"'\n", "?\"") + end + def test_string_literal assert_format("'string'\n", "\"string\"") end