From d8a0a484f24cc2fdbdc21899f55d5aa5c42a75d7 Mon Sep 17 00:00:00 2001 From: toshimaru Date: Thu, 16 Nov 2023 09:18:08 +0900 Subject: [PATCH 1/2] fix: Fix NoMethodError for `tokens_to_s` method Calling `tokens_to_s` gets an error if `token_stream` is nil: ``` undefined method `compact' for nil:NilClass (NoMethodError) ``` So, fall back to an empty array if `@token_stream` is nil. --- lib/rdoc/token_stream.rb | 2 +- test/rdoc/test_rdoc_token_stream.rb | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/rdoc/token_stream.rb b/lib/rdoc/token_stream.rb index 8fc6eadd85..1ff4b0d09e 100644 --- a/lib/rdoc/token_stream.rb +++ b/lib/rdoc/token_stream.rb @@ -105,7 +105,7 @@ def pop_token # Current token stream def token_stream - @token_stream + @token_stream || [] end ## diff --git a/test/rdoc/test_rdoc_token_stream.rb b/test/rdoc/test_rdoc_token_stream.rb index 29c5047fb5..dafbe22323 100644 --- a/test/rdoc/test_rdoc_token_stream.rb +++ b/test/rdoc/test_rdoc_token_stream.rb @@ -53,5 +53,14 @@ def initialize end.new assert_equal "foo 'bar'", foo.tokens_to_s + + foo = Class.new do + include RDoc::TokenStream + + def initialize + @token_stream = nil + end + end.new + assert_equal "", foo.tokens_to_s end end From ca3f1e3ecf0355de0d88a811fddd02d16e783fdf Mon Sep 17 00:00:00 2001 From: toshimaru Date: Thu, 16 Nov 2023 09:18:42 +0900 Subject: [PATCH 2/2] chore: Remove unnecessary argument for `join` method --- lib/rdoc/token_stream.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rdoc/token_stream.rb b/lib/rdoc/token_stream.rb index 1ff4b0d09e..adeef5b660 100644 --- a/lib/rdoc/token_stream.rb +++ b/lib/rdoc/token_stream.rb @@ -112,7 +112,7 @@ def token_stream # Returns a string representation of the token stream def tokens_to_s - token_stream.compact.map { |token| token[:text] }.join '' + token_stream.compact.map { |token| token[:text] }.join end end