Commit 8a24f366 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Avoid crash when unfinished regex or string in source.

parent c73040ae
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -127,12 +127,12 @@ module JsDuck
        elsif @input.check(/'/)
          return {
            :type => :string,
            :value => @input.scan(/'([^'\\]|\\.)*'/m).sub(/^'(.*)'$/m, "\\1")
            :value => @input.scan(/'([^'\\]|\\.)*('|\Z)/m).gsub(/\A'|'\Z/m, "")
          }
        elsif @input.check(/"/)
          return {
            :type => :string,
            :value => @input.scan(/"([^"\\]|\\.)*"/m).sub(/^"(.*)"$/m, "\\1")
            :value => @input.scan(/"([^"\\]|\\.)*("|\Z)/m).gsub(/\A"|"\Z/m, "")
          }
        elsif @input.check(/\//)
          # Several things begin with dash:
@@ -153,7 +153,7 @@ module JsDuck
          elsif regex?
            return {
              :type => :regex,
              :value => @input.scan(/\/([^\/\\]|\\.)*\/[gim]*/)
              :value => @input.scan(/\/([^\/\\]|\\.)*(\/[gim]*|\Z)/)
            }
          else
            return {
+12 −0
Original line number Diff line number Diff line
@@ -151,6 +151,18 @@ describe JsDuck::Lexer do
    it "doc-comment" do
      lex("/** ").should == [[:doc_comment, "/** ", 1]]
    end

    it "regex" do
      lex("/[a-z] ").should == [[:regex, "/[a-z] "]]
    end

    it "single-quoted string" do
      lex("' ").should == [[:string, " "]]
    end

    it "double-quoted string" do
      lex('" ').should == [[:string, " "]]
    end
  end

  describe "passing StringScanner to constructor" do