From d6296601c5f33a827249a0c032ecd77237c7a3f0 Mon Sep 17 00:00:00 2001 From: Hartley McGuire Date: Fri, 23 Dec 2022 15:47:35 -0500 Subject: [PATCH] Fix all 'assigned but unused variable' warnings - The variables in content_location_parser appear to have been copied from content_disposition_parser but are unused - Ragel seems to always generate a useless testEof variable. The `if false` trick is also used in whitequark/parser@21581a2 to suppress the warning. As mentioned in the parser commit, `if false` will not actually generate instructions and so it has no runtime cost. Co-authored-by: Guilherme Quirino --- lib/mail/parsers/address_lists_parser.rb | 4 ++++ lib/mail/parsers/address_lists_parser.rl | 4 ++++ lib/mail/parsers/content_disposition_parser.rb | 4 ++++ lib/mail/parsers/content_disposition_parser.rl | 4 ++++ lib/mail/parsers/content_location_parser.rb | 6 +++++- lib/mail/parsers/content_location_parser.rl | 6 +++++- lib/mail/parsers/content_transfer_encoding_parser.rb | 4 ++++ lib/mail/parsers/content_transfer_encoding_parser.rl | 4 ++++ lib/mail/parsers/content_type_parser.rb | 4 ++++ lib/mail/parsers/content_type_parser.rl | 4 ++++ lib/mail/parsers/date_time_parser.rb | 4 ++++ lib/mail/parsers/date_time_parser.rl | 4 ++++ lib/mail/parsers/envelope_from_parser.rb | 4 ++++ lib/mail/parsers/envelope_from_parser.rl | 4 ++++ lib/mail/parsers/message_ids_parser.rb | 4 ++++ lib/mail/parsers/message_ids_parser.rl | 4 ++++ lib/mail/parsers/mime_version_parser.rb | 4 ++++ lib/mail/parsers/mime_version_parser.rl | 4 ++++ lib/mail/parsers/phrase_lists_parser.rb | 4 ++++ lib/mail/parsers/phrase_lists_parser.rl | 4 ++++ lib/mail/parsers/received_parser.rb | 4 ++++ lib/mail/parsers/received_parser.rl | 4 ++++ spec/mail/network/delivery_methods/smtp_connection_spec.rb | 2 -- 23 files changed, 90 insertions(+), 4 deletions(-) diff --git a/lib/mail/parsers/address_lists_parser.rb b/lib/mail/parsers/address_lists_parser.rb index 1665333da..c49340fc5 100644 --- a/lib/mail/parsers/address_lists_parser.rb +++ b/lib/mail/parsers/address_lists_parser.rb @@ -33228,6 +33228,10 @@ def self.parse(data) end end + if false + testEof + end + if p != eof || cs < 2461 raise Mail::Field::IncompleteParseError.new(Mail::AddressList, data, p) end diff --git a/lib/mail/parsers/address_lists_parser.rl b/lib/mail/parsers/address_lists_parser.rl index b619947f1..6d44ae222 100644 --- a/lib/mail/parsers/address_lists_parser.rl +++ b/lib/mail/parsers/address_lists_parser.rl @@ -165,6 +165,10 @@ module Mail::Parsers %%write init; %%write exec; + if false + testEof + end + if p != eof || cs < %%{ write first_final; }%% raise Mail::Field::IncompleteParseError.new(Mail::AddressList, data, p) end diff --git a/lib/mail/parsers/content_disposition_parser.rb b/lib/mail/parsers/content_disposition_parser.rb index e95e640b0..e2f81ea6b 100644 --- a/lib/mail/parsers/content_disposition_parser.rb +++ b/lib/mail/parsers/content_disposition_parser.rb @@ -887,6 +887,10 @@ def self.parse(data) end end + if false + testEof + end + if p != eof || cs < 40 raise Mail::Field::IncompleteParseError.new(Mail::ContentDispositionElement, data, p) end diff --git a/lib/mail/parsers/content_disposition_parser.rl b/lib/mail/parsers/content_disposition_parser.rl index 431893d50..c53c9a576 100644 --- a/lib/mail/parsers/content_disposition_parser.rl +++ b/lib/mail/parsers/content_disposition_parser.rl @@ -75,6 +75,10 @@ module Mail::Parsers %%write init; %%write exec; + if false + testEof + end + if p != eof || cs < %%{ write first_final; }%% raise Mail::Field::IncompleteParseError.new(Mail::ContentDispositionElement, data, p) end diff --git a/lib/mail/parsers/content_location_parser.rb b/lib/mail/parsers/content_location_parser.rb index 8cc4b15f6..f10a43850 100644 --- a/lib/mail/parsers/content_location_parser.rb +++ b/lib/mail/parsers/content_location_parser.rb @@ -588,7 +588,7 @@ def self.parse(data) return content_location if Mail::Utilities.blank?(data) # Parser state - disp_type_s = param_attr_s = param_attr = qstr_s = qstr = param_val_s = nil + qstr_s = qstr = param_val_s = nil # 5.1 Variables Used by Ragel p = 0 @@ -808,6 +808,10 @@ def self.parse(data) end end + if false + testEof + end + if p != eof || cs < 32 raise Mail::Field::IncompleteParseError.new(Mail::ContentLocationElement, data, p) end diff --git a/lib/mail/parsers/content_location_parser.rl b/lib/mail/parsers/content_location_parser.rl index 4fb035472..816a18345 100644 --- a/lib/mail/parsers/content_location_parser.rl +++ b/lib/mail/parsers/content_location_parser.rl @@ -54,7 +54,7 @@ module Mail::Parsers return content_location if Mail::Utilities.blank?(data) # Parser state - disp_type_s = param_attr_s = param_attr = qstr_s = qstr = param_val_s = nil + qstr_s = qstr = param_val_s = nil # 5.1 Variables Used by Ragel p = 0 @@ -64,6 +64,10 @@ module Mail::Parsers %%write init; %%write exec; + if false + testEof + end + if p != eof || cs < %%{ write first_final; }%% raise Mail::Field::IncompleteParseError.new(Mail::ContentLocationElement, data, p) end diff --git a/lib/mail/parsers/content_transfer_encoding_parser.rb b/lib/mail/parsers/content_transfer_encoding_parser.rb index bcda478f4..18c149436 100644 --- a/lib/mail/parsers/content_transfer_encoding_parser.rb +++ b/lib/mail/parsers/content_transfer_encoding_parser.rb @@ -508,6 +508,10 @@ def self.parse(data) end end + if false + testEof + end + if p != eof || cs < 21 raise Mail::Field::IncompleteParseError.new(Mail::ContentTransferEncodingElement, data, p) end diff --git a/lib/mail/parsers/content_transfer_encoding_parser.rl b/lib/mail/parsers/content_transfer_encoding_parser.rl index f20dd0378..d13143665 100644 --- a/lib/mail/parsers/content_transfer_encoding_parser.rl +++ b/lib/mail/parsers/content_transfer_encoding_parser.rl @@ -57,6 +57,10 @@ module Mail::Parsers %%write init; %%write exec; + if false + testEof + end + if p != eof || cs < %%{ write first_final; }%% raise Mail::Field::IncompleteParseError.new(Mail::ContentTransferEncodingElement, data, p) end diff --git a/lib/mail/parsers/content_type_parser.rb b/lib/mail/parsers/content_type_parser.rb index 75a81e324..18a1361fb 100644 --- a/lib/mail/parsers/content_type_parser.rb +++ b/lib/mail/parsers/content_type_parser.rb @@ -1034,6 +1034,10 @@ def self.parse(data) end end + if false + testEof + end + if p != eof || cs < 47 raise Mail::Field::IncompleteParseError.new(Mail::ContentTypeElement, data, p) end diff --git a/lib/mail/parsers/content_type_parser.rl b/lib/mail/parsers/content_type_parser.rl index 724e43df2..222b7c86c 100644 --- a/lib/mail/parsers/content_type_parser.rl +++ b/lib/mail/parsers/content_type_parser.rl @@ -76,6 +76,10 @@ module Mail::Parsers %%write init; %%write exec; + if false + testEof + end + if p != eof || cs < %%{ write first_final; }%% raise Mail::Field::IncompleteParseError.new(Mail::ContentTypeElement, data, p) end diff --git a/lib/mail/parsers/date_time_parser.rb b/lib/mail/parsers/date_time_parser.rb index 8afd91d0c..ffe8ecc70 100644 --- a/lib/mail/parsers/date_time_parser.rb +++ b/lib/mail/parsers/date_time_parser.rb @@ -877,6 +877,10 @@ def self.parse(data) end end + if false + testEof + end + if p != eof || cs < 103 raise Mail::Field::IncompleteParseError.new(Mail::DateTimeElement, data, p) end diff --git a/lib/mail/parsers/date_time_parser.rl b/lib/mail/parsers/date_time_parser.rl index 44b80c6e5..afdef0088 100644 --- a/lib/mail/parsers/date_time_parser.rl +++ b/lib/mail/parsers/date_time_parser.rl @@ -55,6 +55,10 @@ module Mail::Parsers %%write init; %%write exec; + if false + testEof + end + if p != eof || cs < %%{ write first_final; }%% raise Mail::Field::IncompleteParseError.new(Mail::DateTimeElement, data, p) end diff --git a/lib/mail/parsers/envelope_from_parser.rb b/lib/mail/parsers/envelope_from_parser.rb index fa224c431..e121eae78 100644 --- a/lib/mail/parsers/envelope_from_parser.rb +++ b/lib/mail/parsers/envelope_from_parser.rb @@ -3661,6 +3661,10 @@ def self.parse(data) end end + if false + testEof + end + if p != eof || cs < 257 raise Mail::Field::IncompleteParseError.new(Mail::EnvelopeFromElement, data, p) end diff --git a/lib/mail/parsers/envelope_from_parser.rl b/lib/mail/parsers/envelope_from_parser.rl index d88eb0142..4362db8db 100644 --- a/lib/mail/parsers/envelope_from_parser.rl +++ b/lib/mail/parsers/envelope_from_parser.rl @@ -75,6 +75,10 @@ module Mail::Parsers %%write init; %%write exec; + if false + testEof + end + if p != eof || cs < %%{ write first_final; }%% raise Mail::Field::IncompleteParseError.new(Mail::EnvelopeFromElement, data, p) end diff --git a/lib/mail/parsers/message_ids_parser.rb b/lib/mail/parsers/message_ids_parser.rb index f265f9196..aa2dbf6d3 100644 --- a/lib/mail/parsers/message_ids_parser.rb +++ b/lib/mail/parsers/message_ids_parser.rb @@ -5147,6 +5147,10 @@ def self.parse(data) end end + if false + testEof + end + if p != eof || cs < 318 raise Mail::Field::IncompleteParseError.new(Mail::MessageIdsElement, data, p) end diff --git a/lib/mail/parsers/message_ids_parser.rl b/lib/mail/parsers/message_ids_parser.rl index 1e3432294..299636b65 100644 --- a/lib/mail/parsers/message_ids_parser.rl +++ b/lib/mail/parsers/message_ids_parser.rl @@ -79,6 +79,10 @@ module Mail::Parsers %%write init; %%write exec; + if false + testEof + end + if p != eof || cs < %%{ write first_final; }%% raise Mail::Field::IncompleteParseError.new(Mail::MessageIdsElement, data, p) end diff --git a/lib/mail/parsers/mime_version_parser.rb b/lib/mail/parsers/mime_version_parser.rb index 9c915dd62..42dcb44f4 100644 --- a/lib/mail/parsers/mime_version_parser.rb +++ b/lib/mail/parsers/mime_version_parser.rb @@ -499,6 +499,10 @@ def self.parse(data) end end + if false + testEof + end + if p != eof || cs < 23 raise Mail::Field::IncompleteParseError.new(Mail::MimeVersionElement, data, p) end diff --git a/lib/mail/parsers/mime_version_parser.rl b/lib/mail/parsers/mime_version_parser.rl index c69d3f009..eb5a33ce9 100644 --- a/lib/mail/parsers/mime_version_parser.rl +++ b/lib/mail/parsers/mime_version_parser.rl @@ -54,6 +54,10 @@ module Mail::Parsers %%write init; %%write exec; + if false + testEof + end + if p != eof || cs < %%{ write first_final; }%% raise Mail::Field::IncompleteParseError.new(Mail::MimeVersionElement, data, p) end diff --git a/lib/mail/parsers/phrase_lists_parser.rb b/lib/mail/parsers/phrase_lists_parser.rb index 0f66d3be5..a54733f2c 100644 --- a/lib/mail/parsers/phrase_lists_parser.rb +++ b/lib/mail/parsers/phrase_lists_parser.rb @@ -870,6 +870,10 @@ def self.parse(data) end end + if false + testEof + end + if p != eof || cs < 42 raise Mail::Field::IncompleteParseError.new(Mail::PhraseList, data, p) end diff --git a/lib/mail/parsers/phrase_lists_parser.rl b/lib/mail/parsers/phrase_lists_parser.rl index 722c3bbee..a897d3bcd 100644 --- a/lib/mail/parsers/phrase_lists_parser.rl +++ b/lib/mail/parsers/phrase_lists_parser.rl @@ -76,6 +76,10 @@ module Mail::Parsers %%write init; %%write exec; + if false + testEof + end + if p != eof || cs < %%{ write first_final; }%% raise Mail::Field::IncompleteParseError.new(Mail::PhraseList, data, p) end diff --git a/lib/mail/parsers/received_parser.rb b/lib/mail/parsers/received_parser.rb index b24c2f5b7..e998fe20a 100644 --- a/lib/mail/parsers/received_parser.rb +++ b/lib/mail/parsers/received_parser.rb @@ -8768,6 +8768,10 @@ def self.parse(data) end end + if false + testEof + end + if p != eof || cs < 648 raise Mail::Field::IncompleteParseError.new(Mail::ReceivedElement, data, p) end diff --git a/lib/mail/parsers/received_parser.rl b/lib/mail/parsers/received_parser.rl index 83242e7a8..0df1c242d 100644 --- a/lib/mail/parsers/received_parser.rl +++ b/lib/mail/parsers/received_parser.rl @@ -77,6 +77,10 @@ module Mail::Parsers %%write init; %%write exec; + if false + testEof + end + if p != eof || cs < %%{ write first_final; }%% raise Mail::Field::IncompleteParseError.new(Mail::ReceivedElement, data, p) end diff --git a/spec/mail/network/delivery_methods/smtp_connection_spec.rb b/spec/mail/network/delivery_methods/smtp_connection_spec.rb index 655adc65d..cf4ee857b 100644 --- a/spec/mail/network/delivery_methods/smtp_connection_spec.rb +++ b/spec/mail/network/delivery_methods/smtp_connection_spec.rb @@ -16,8 +16,6 @@ end it "should not dot-stuff unterminated last line with no leading dot" do - body = "this is a test\n.\nonly a test" - Mail.deliver do from 'from@example.com' to 'to@example.com'