Skip to content

Commit

Permalink
Fix bug with escaping strings. Slightly better now, but not bug free,…
Browse files Browse the repository at this point in the history
… details in the commented spec.
  • Loading branch information
utkarshkukreti committed Jun 1, 2011
1 parent 501e27a commit 25ed7f2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/phaad/generator.rb
Expand Up @@ -54,7 +54,7 @@ def process(sexp)
when :@int, :@float
emit sexp[1]
when :@tstring_content
emit "\"#{sexp[1]}\""
emit "\"#{sexp[1].gsub('"', '\"')}\""
when :string_content
sexp[1..-1].each_with_index do |exp, i|
unless exp[0] == :string_embexpr && exp[1][0][0] == :void_stmt
Expand Down
15 changes: 15 additions & 0 deletions spec/generator/string_spec.rb
@@ -1,6 +1,21 @@
require 'spec_helper'

describe Phaad::Generator, 'string' do
context "escaping" do
it "should parse double quotes" do
compile(%q{'"'}).should == %q{"\"";}
compile(%q{'\"'}).should == %q{"\\\"";}
compile(%q{'\\"'}).should == %q{"\\\"";}
end

##
# Ripper parses single quotes the same as double quotes. There's no way to
# know if a single quote was used or a double quote was.
# it "should respect escape sequences in single and double quotes" do
# compile(%q{"\n"}).should == %q{"\\n";}
# compile(%q{'\n'}).should == %q{"\\\\n";}
# end
end
context "string interpolation" do
it "should parse simple interpolation" do
compile('"a #{b}"').should == '"a " . $b;'
Expand Down

0 comments on commit 25ed7f2

Please sign in to comment.