Skip to content

Fix backtick handling #475

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Aug 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/rdoc/ruby_lex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1311,7 +1311,7 @@ def identify_string(ltype, quoted = ltype, type = nil)
@ltype = ltype
@quoted = quoted

str = if ltype == quoted and %w[" ' /].include? ltype then
str = if ltype == quoted and %w[" ' / `].include? ltype then
ltype.dup
else
"%#{type}#{PERCENT_PAREN_REV[quoted]||quoted}"
Expand Down
1 change: 1 addition & 0 deletions lib/rdoc/token_stream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def self.to_html token_stream
when RDoc::RubyToken::TkDREGEXP then 'ruby-regexp'
when RDoc::RubyToken::TkNode then 'ruby-node'
when RDoc::RubyToken::TkCOMMENT then 'ruby-comment'
when RDoc::RubyToken::TkXSTRING then 'ruby-string'
when RDoc::RubyToken::TkSTRING then 'ruby-string'
when RDoc::RubyToken::TkVal then 'ruby-value'
end
Expand Down
40 changes: 40 additions & 0 deletions test/test_rdoc_markup_to_html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,46 @@ def bar
assert_equal expected, @to.res.join
end

def test_accept_verbatim_escape_in_backtick
code = <<-'RUBY'
def foo
[
`\\`,
`\'\"\``,
`\#`,
`\#{}`,
`#`,
`#{}`
]
end
def bar
end
RUBY
verb = @RM::Verbatim.new(*code.split(/(?<=\n)/))

@to.start_accepting
@to.accept_verbatim verb

expected = <<-'EXPECTED'

<pre class="ruby"><span class="ruby-keyword">def</span> <span class="ruby-identifier">foo</span>
[
<span class="ruby-string">`\\`</span>,
<span class="ruby-string">`\&#39;\&quot;\``</span>,
<span class="ruby-string">`\#`</span>,
<span class="ruby-string">`\#{}`</span>,
<span class="ruby-string">`#`</span>,
<span class="ruby-node">`#{}`</span>
]
<span class="ruby-keyword">end</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">bar</span>
<span class="ruby-keyword">end</span>
</pre>
EXPECTED

assert_equal expected, @to.res.join
end

def test_accept_verbatim_ruby
verb = @RM::Verbatim.new("1 + 1\n")
verb.format = :ruby
Expand Down
45 changes: 45 additions & 0 deletions test/test_rdoc_ruby_lex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,51 @@ def test_class_tokenize_string_with_escape
assert_equal expected, tokens
end

def test_class_tokenize_backtick_with_escape
tokens = RDoc::RubyLex.tokenize <<'RUBY', nil
[
`\\`,
`\'\"\``,
`\#`,
`\#{}`,
`#`,
`#{}`
]
RUBY

expected = [
@TK::TkLBRACK .new( 0, 1, 0, "["),
@TK::TkNL .new( 1, 1, 1, "\n"),
@TK::TkSPACE .new( 2, 2, 0, " "),
@TK::TkXSTRING .new( 4, 2, 2, "`\\\\`"),
@TK::TkCOMMA .new( 8, 2, 6, ","),
@TK::TkNL .new( 9, 2, 2, "\n"),
@TK::TkSPACE .new(10, 3, 0, " "),
@TK::TkXSTRING .new(12, 3, 2, "`\\'\\\"\\``"),
@TK::TkCOMMA .new(20, 3, 10, ","),
@TK::TkNL .new(21, 3, 10, "\n"),
@TK::TkSPACE .new(22, 4, 0, " "),
@TK::TkXSTRING .new(24, 4, 2, "`\\#`"),
@TK::TkCOMMA .new(28, 4, 6, ","),
@TK::TkNL .new(29, 4, 22, "\n"),
@TK::TkSPACE .new(30, 5, 0, " "),
@TK::TkXSTRING .new(32, 5, 2, "`\\\#{}`"),
@TK::TkCOMMA .new(38, 5, 8, ","),
@TK::TkNL .new(39, 5, 30, "\n"),
@TK::TkSPACE .new(40, 6, 0, " "),
@TK::TkXSTRING .new(42, 6, 2, "`#`"),
@TK::TkCOMMA .new(45, 6, 5, ","),
@TK::TkNL .new(46, 6, 40, "\n"),
@TK::TkSPACE .new(47, 7, 0, " "),
@TK::TkDXSTRING.new(49, 7, 2, "`\#{}`"),
@TK::TkNL .new(54, 7, 7, "\n"),
@TK::TkRBRACK .new(55, 8, 0, "]"),
@TK::TkNL .new(56, 8, 55, "\n")
]

assert_equal expected, tokens
end

def test_class_tokenize_string_escape
tokens = RDoc::RubyLex.tokenize '"\\n"', nil
assert_equal @TK::TkSTRING.new( 0, 1, 0, "\"\\n\""), tokens.first
Expand Down