Fix rdoc parsing of nil text tokens.

With ruby < 2.6.0 / rdoc < 6.0.2, rdoc fails to parse valid ruby code,
resulting in spurious build failures.  An example is asciidoctor >
2.0.15 (though 2.0.20, currently)

While attempting to build asciidoctor-2.0.20 for Fedora and RHEL+EPEL
releases, the following error fails the build on RHEL+EPEL 8:

    Installing ri documentation for asciidoctor-2.0.20
    Installing darkfish documentation for asciidoctor-2.0.20
    ERROR:  While executing gem ... (RDoc::Error)
        error generating Asciidoctor/Converter/ManPageConverter.html:
        no implicit conversion of nil into String (TypeError)

Resolves: rhbz#2210326
This commit is contained in:
Todd Zullinger 2023-05-25 23:47:26 -04:00 committed by Jarek Prokop
parent 5eba2e7338
commit 1024e138f4
2 changed files with 78 additions and 1 deletions

View File

@ -0,0 +1,69 @@
From 9d98bfe7f1abdeda5aedf9404588104980ee7a86 Mon Sep 17 00:00:00 2001
From: aycabta <aycabta@gmail.com>
Date: Mon, 15 Jan 2018 22:32:56 +0900
Subject: [PATCH] Check nil text token
Sometimes :on_ignored_nl token has nil text. This commit checks and
bypasses the token.
---
lib/rdoc/parser/ripper_state_lex.rb | 4 +++-
test/test_rdoc_parser_ruby.rb | 30 +++++++++++++++++++++++++++++
2 files changed, 33 insertions(+), 1 deletion(-)
diff --git a/lib/rdoc/parser/ripper_state_lex.rb b/lib/rdoc/parser/ripper_state_lex.rb
index 2a285b97a4..c56cef46ee 100644
--- a/lib/rdoc/parser/ripper_state_lex.rb
+++ b/lib/rdoc/parser/ripper_state_lex.rb
@@ -330,8 +330,10 @@ class RDoc::RipperStateLex
@heredoc_queue << retrieve_heredoc_info(tk)
@inner_lex.lex_state = EXPR_END unless RIPPER_HAS_LEX_STATE
when :on_nl, :on_ignored_nl, :on_comment, :on_heredoc_end then
- unless @heredoc_queue.empty?
+ if !@heredoc_queue.empty?
get_heredoc_tk(*@heredoc_queue.shift)
+ elsif tk[:text].nil? # :on_ignored_nl sometimes gives nil
+ tk[:text] = ''
end
when :on_words_beg then
tk = get_words_tk(tk)
diff --git a/test/rdoc/test_rdoc_parser_ruby.rb b/test/rdoc/test_rdoc_parser_ruby.rb
index 833ed2cc74..c9d57021ce 100644
--- a/test/rdoc/test_rdoc_parser_ruby.rb
+++ b/test/rdoc/test_rdoc_parser_ruby.rb
@@ -306,6 +306,36 @@ def sum(n)
assert_equal @top_level, sum.file
end
+ def test_parse_on_ignored_nl_with_nil_text
+ util_parser <<ruby
+class Foo
+ def meth
+ variable # comment
+ .chain
+ end
+end
+ruby
+
+ expected = <<EXPECTED
+<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">meth</span>
+ <span class="ruby-identifier">variable</span> <span class="ruby-comment"># comment</span>
+ .<span class="ruby-identifier">chain</span>
+<span class="ruby-keyword">end</span>
+EXPECTED
+ expected = expected.rstrip
+
+ @parser.scan
+
+ foo = @store.find_class_named 'Foo'
+ meth = foo.method_list.first
+
+ assert_equal 'meth', meth.name
+ assert_equal @top_level, meth.file
+
+ markup_code = meth.markup_code.sub(/^.*\n/, '')
+ assert_equal expected, markup_code
+ end
+
def test_parse_alias
klass = RDoc::NormalClass.new 'Foo'
klass.parent = @top_level

View File

@ -21,7 +21,7 @@
%endif %endif
%global release 110 %global release 111
%{!?release_string:%global release_string %{?development_release:0.}%{release}%{?development_release:.%{development_release}}%{?dist}} %{!?release_string:%global release_string %{?development_release:0.}%{release}%{?development_release:.%{development_release}}%{?dist}}
@ -198,6 +198,9 @@ Patch33: ruby-2.6.9-date-2.0.1-parse-length-limit.patch
# https://github.com/ruby/ruby/commit/02c341c9bc5879eae568ed2ba02cf227ed948199 # https://github.com/ruby/ruby/commit/02c341c9bc5879eae568ed2ba02cf227ed948199
# https://github.com/ruby/cgi/commit/84dedc6fbb2a210ec070c35bc607b89003701fa2 # https://github.com/ruby/cgi/commit/84dedc6fbb2a210ec070c35bc607b89003701fa2
Patch34: ruby-2.6.9-cgi-0.1.1-cookie-parse-not-decode-names.patch Patch34: ruby-2.6.9-cgi-0.1.1-cookie-parse-not-decode-names.patch
# Fix rdoc nil token parsing
# https://github.com/ruby/rdoc/commit/a1631aa98a67112d96ac101c72909fdeec6f84f9
Patch35: ruby-2.6.0-rdoc-6.0.2-check-nil-text-token.patch
Requires: %{name}-libs%{?_isa} = %{version}-%{release} Requires: %{name}-libs%{?_isa} = %{version}-%{release}
Suggests: rubypick Suggests: rubypick
@ -602,6 +605,7 @@ sed -i 's/"evaluation\/incorrect_words.yaml"\.freeze, //' \
%patch32 -p1 %patch32 -p1
%patch33 -p1 %patch33 -p1
%patch34 -p1 %patch34 -p1
%patch35 -p1
# Provide an example of usage of the tapset: # Provide an example of usage of the tapset:
cp -a %{SOURCE3} . cp -a %{SOURCE3} .
@ -1154,6 +1158,10 @@ OPENSSL_SYSTEM_CIPHERS_OVERRIDE=xyz_nonexistent_file OPENSSL_CONF='' \
%{gem_dir}/specifications/xmlrpc-%{xmlrpc_version}.gemspec %{gem_dir}/specifications/xmlrpc-%{xmlrpc_version}.gemspec
%changelog %changelog
* Thu May 25 2023 Todd Zullinger <tmz@pobox.com> - 2.5.9-111
- Fix rdoc parsing of nil text tokens.
Resolves: rhbz#2210326
* Fri Jul 08 2022 Jun Aruga <jaruga@redhat.com> - 2.5.9-110 * Fri Jul 08 2022 Jun Aruga <jaruga@redhat.com> - 2.5.9-110
- Fix FTBFS due to an incompatible load directive. - Fix FTBFS due to an incompatible load directive.
- Fix a fiddle import test on an optimized glibc on Power 9. - Fix a fiddle import test on an optimized glibc on Power 9.