Commit 5bc15b50 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Don't eval strings in Lexer.

JavaScript and Ruby rules for strings differ, so that a valid JS
string can be an invalid Ruby string.

So for now just taking the text inside quotes to be the value of
string.
parent 6e667eb8
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -97,12 +97,12 @@ module JsDuck
        elsif @input.check(/'/)
          @tokens << {
            :type => :string,
            :value => eval(@input.scan(/'([^'\\]|\\.)*'/))
            :value => @input.scan(/'([^'\\]|\\.)*'/).sub(/^'(.*)'$/, "\\1")
          }
        elsif @input.check(/"/)
          @tokens << {
            :type => :string,
            :value => eval(@input.scan(/"([^"\\]|\\.)*"/))
            :value => @input.scan(/"([^"\\]|\\.)*"/).sub(/^"(.*)"$/, "\\1")
          }
        elsif @input.check(/\//)
          # Several things begin with dash:
+2 −2
Original line number Diff line number Diff line
@@ -83,11 +83,11 @@ describe JsDuck::Lexer do
    end

    it "when escaped double-quote inside double-quoted string" do
      lex(@d+@b+@d+@d   + ' "blah"').should == [[:string, @d], [:string, "blah"]]
      lex(@d+@b+@d+@d   + ' "blah"').should == [[:string, @b+@d], [:string, "blah"]]
    end

    it "when escaped single-quote inside single-quoted string" do
      lex(@s+@b+@s+@s   + ' "blah"').should == [[:string, @s], [:string, "blah"]]
      lex(@s+@b+@s+@s   + ' "blah"').should == [[:string, @b+@s], [:string, "blah"]]
    end
  end