Do not parse non-Ruby files as Ruby when :markup: is markdown or tomdoc - #1772
Open
sjh9714 wants to merge 1 commit into
Open
Do not parse non-Ruby files as Ruby when :markup: is markdown or tomdoc#1772sjh9714 wants to merge 1 commit into
sjh9714 wants to merge 1 commit into
Conversation
RDoc::Parser.for consulted use_markup before any file-name-based selection, and use_markup unconditionally mapped the markdown and tomdoc markup formats to the Ruby parser. A C file with /* :markup: markdown */ in its first three lines was therefore parsed as Ruby source. Pass the file name into use_markup and return the Ruby parser for these formats only when the file name selects the Ruby parser (or when no file name is given, preserving the documented behavior for direct callers). Other files fall through to the regular shebang and extension logic, so the C file above is parsed as C while the :markup: directive still sets the comment format.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1597.
A file whose first three lines contain
:markup: markdown(ortomdoc) was always handed to the Ruby parser:RDoc::Parser.forconsultsuse_markupbefore any file-name-based selection, anduse_markupnever sees the file name. The issue'sfile.cwas therefore documented as Ruby source. The buggy line carried# TODO Ruby should be returned only when the filename is correct.This change passes the file name into
use_markupand returns the Ruby parser for these two markups only when the file name actually selects the Ruby parser. Other files fall through tofor's existing shebang/extension logic, sofile.cis parsed by the C parser — while the:markup:directive still sets the comment format, since that is handled independently byRDoc::Markup::PreProcess(its directive regexp already matches/* */comments).Prior art: #1613 attempted this and was self-closed over the parser-vs-format conflation; gating only the parser choice on the file name and leaving format handling to PreProcess avoids that problem.
Behavior notes:
.rb/.rbwfiles and extensionless scripts with a Ruby shebang keep the Ruby parser (the shebang branch inforis unchanged).README.mdwith a markup comment was previously also parsed as Ruby; it now falls through to the Markdown parser.use_markup(content)without a file name (existing public API) behaves as before.Changes
RDoc::Parser.use_markupaccepts an optionalfile_nameand consultscan_parse_by_namefor themarkdown/tomdocmarkups;RDoc::Parser.forpasses the file name through..cfile with/* :markup: markdown */selectsRDoc::Parser::Cend to end (fails on master withRDoc::Parser::Ruby), plususe_markupunit coverage for.rbvs.cwith both markups.Testing
bundle exec ruby -Ilib -Itest test/rdoc/parser/parser_test.rbbundle exec rake(2520 unit tests + 20 RubyGems integration tests, 100% pass)bundle exec rubocop lib/rdoc/parser.rb test/rdoc/parser/parser_test.rb