Merge branch 'fix_lexer'
This commit is contained in:
commit
358334add3
|
@ -14,10 +14,12 @@ module Pigeon
|
||||||
@tokens = []
|
@tokens = []
|
||||||
@state = HEADER
|
@state = HEADER
|
||||||
@last_good = :START
|
@last_good = :START
|
||||||
|
@loops = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
def tokenize
|
def tokenize
|
||||||
until scanner.eos?
|
until scanner.eos?
|
||||||
|
safety_check
|
||||||
case @state
|
case @state
|
||||||
when HEADER then do_header
|
when HEADER then do_header
|
||||||
when BODY then do_body
|
when BODY then do_body
|
||||||
|
@ -30,6 +32,7 @@ module Pigeon
|
||||||
|
|
||||||
def tokenize_unsigned(signature)
|
def tokenize_unsigned(signature)
|
||||||
until scanner.eos?
|
until scanner.eos?
|
||||||
|
safety_check
|
||||||
case @state
|
case @state
|
||||||
when HEADER then do_header
|
when HEADER then do_header
|
||||||
when BODY then do_body
|
when BODY then do_body
|
||||||
|
@ -42,6 +45,14 @@ module Pigeon
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def safety_check
|
||||||
|
if @loops > 1000
|
||||||
|
raise "RUNAWAY LOOP DETECTED"
|
||||||
|
else
|
||||||
|
@loops += 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
attr_reader :bundle_string, :scanner, :tokens
|
attr_reader :bundle_string, :scanner, :tokens
|
||||||
# TODO: Change all the `{40,90}` values in ::Lexer to real values
|
# TODO: Change all the `{40,90}` values in ::Lexer to real values
|
||||||
# TODO: Create regexes using string and Regexp.new() for cleaner regexes.
|
# TODO: Create regexes using string and Regexp.new() for cleaner regexes.
|
||||||
|
@ -167,6 +178,7 @@ module Pigeon
|
||||||
@state = HEADER
|
@state = HEADER
|
||||||
maybe_end_message!
|
maybe_end_message!
|
||||||
@last_good = :FOOTER_SEPERATOR
|
@last_good = :FOOTER_SEPERATOR
|
||||||
|
@loops = 0
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -167,14 +167,13 @@ RSpec.describe Pigeon::Message do
|
||||||
# This was originally a bug nooted during development
|
# This was originally a bug nooted during development
|
||||||
# That caused a runaway loop in the tokenizer.
|
# That caused a runaway loop in the tokenizer.
|
||||||
it "handles this key: '\\nVUx0hC3'" do
|
it "handles this key: '\\nVUx0hC3'" do
|
||||||
pending("Known bug- will fix after writing docs.")
|
|
||||||
db.delete_current_draft
|
db.delete_current_draft
|
||||||
db.new_draft(kind: "unit_test")
|
db.new_draft(kind: "unit_test")
|
||||||
db.update_draft("\nVUx0hC3", "n")
|
db.update_draft("\nVUx0hC3", "n")
|
||||||
db.update_draft("n", "\nVUx0hC3")
|
db.update_draft("n", "\nVUx0hC3")
|
||||||
Timeout::timeout(0.5) do
|
Timeout::timeout(0.5) do
|
||||||
boom = -> { Pigeon::Lexer.tokenize(db.publish_draft.render) }
|
boom = -> { Pigeon::Lexer.tokenize(db.publish_draft.render) }
|
||||||
expect(boom).to raise_error(Pigeon::Lexer::LexError)
|
expect(boom).to raise_error("RUNAWAY LOOP DETECTED")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue