Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Protect parsing of data types from empty lines #375

Merged
merged 1 commit into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading