Skip to content

Commit

Permalink
Protect parsing of data types from empty lines
Browse files Browse the repository at this point in the history
  • Loading branch information
lbetz authored and evgeni committed Sep 16, 2024
1 parent 7884ce8 commit c1ff767
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/kafo/data_type_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def initialize(manifest)
type_line_without_newlines = +''
manifest.each_line do |line|
line = line.force_encoding("UTF-8").strip
next if line.start_with?('#')
next if line.start_with?('#') || line.empty?

line = line.split(' #').first.strip
if line =~ TYPE_DEFINITION
Expand Down
5 changes: 5 additions & 0 deletions test/kafo/data_type_parser_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ module Kafo
it { _(parser.types).must_equal({"IP"=>"Variant[IPv4,IPv6,]", "IPProto"=>"Variant[TCP,UDP,]"}) }
end

describe "parse multiple multiline aliases with empty lines" do
let(:file) { "# We need IP\n \ntype IP = Variant[\n\n IPv4, # Legacy IP\n\n IPv6,\n\n]\n\n# We also need IPProto\n\ntype IPProto = Variant[\n\n TCP,\n\n UDP,\n\n]" }
it { _(parser.types).must_equal({"IP"=>"Variant[IPv4,IPv6,]", "IPProto"=>"Variant[TCP,UDP,]"}) }
end

describe "#register" do
after { DataType.unregister_type('Test') }
let(:file) { 'type Test = String' }
Expand Down

0 comments on commit c1ff767

Please sign in to comment.