From c1ff7673a94a92f8b5c32aab051fe3dd04dbe94d Mon Sep 17 00:00:00 2001 From: Lennart Betz Date: Wed, 28 Aug 2024 13:07:42 +0200 Subject: [PATCH] Protect parsing of data types from empty lines --- lib/kafo/data_type_parser.rb | 2 +- test/kafo/data_type_parser_test.rb | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/kafo/data_type_parser.rb b/lib/kafo/data_type_parser.rb index f790c60e..68d1974b 100644 --- a/lib/kafo/data_type_parser.rb +++ b/lib/kafo/data_type_parser.rb @@ -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 diff --git a/test/kafo/data_type_parser_test.rb b/test/kafo/data_type_parser_test.rb index cdb32ba3..20dcb79f 100644 --- a/test/kafo/data_type_parser_test.rb +++ b/test/kafo/data_type_parser_test.rb @@ -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' }