Skip to content

Commit

Permalink
Merge pull request #12364 from koic/fix_incorrect_rendering_in_format…
Browse files Browse the repository at this point in the history
…ter_html_formatter

[Fix #12363] Fix incorrect rendering in `HTMLFormatter` formatter
  • Loading branch information
koic committed Nov 6, 2023
2 parents d3fb79b + e389a33 commit c0f5b35
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#12363](https://github.com/rubocop/rubocop/issues/12363): Fix incorrect rendering of HTML character entities in `HTMLFormatter` formatter. ([@koic][])
2 changes: 1 addition & 1 deletion lib/rubocop/formatter/html_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def binding
# rubocop:enable Lint/UselessMethodDefinition

def decorated_message(offense)
offense.message.gsub(/`(.+?)`/) { "<code>#{Regexp.last_match(1)}</code>" }
offense.message.gsub(/`(.+?)`/) { "<code>#{escape(Regexp.last_match(1))}</code>" }
end

def highlighted_source_line(offense)
Expand Down
19 changes: 15 additions & 4 deletions spec/fixtures/html_formatter/expected.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ <h1 class="title">RuboCop Inspection Report</h1>
<div class="infobox">
<div class="total">
3 files inspected,
22 offenses detected:
23 offenses detected:
</div>
<ul class="offenses-list">

Expand All @@ -388,7 +388,7 @@ <h1 class="title">RuboCop Inspection Report</h1>

<li>
<a href="#offense_app/models/book.rb">
app/models/book.rb - 6 offenses
app/models/book.rb - 7 offenses
</a>
</li>

Expand Down Expand Up @@ -596,7 +596,7 @@ <h1 class="title">RuboCop Inspection Report</h1>

<div class="offense-box" id="offense_app/models/book.rb">
<div class="box-title-placeholder"><h3>&nbsp;</h3></div>
<div class="box-title"><h3>app/models/book.rb - 6 offenses</h3></div>
<div class="box-title"><h3>app/models/book.rb - 7 offenses</h3></div>
<div class="offense-reports">

<div class="report">
Expand Down Expand Up @@ -647,6 +647,17 @@ <h1 class="title">RuboCop Inspection Report</h1>
<div class="meta">
<span class="location">Line #4</span>
<span class="severity convention">convention:</span>
<span class="message">Style/RedundantRegexpArgument: Use string <code>&quot;&amp;amp;&amp;lt;&quot;</code> as argument instead of regexp <code>/&amp;amp;&amp;lt;/</code>.</span>
</div>

<pre><code> qux(quux.scan(<span class="highlight convention">/&amp;amp;&amp;lt;/</span>))</code></pre>

</div>

<div class="report">
<div class="meta">
<span class="location">Line #5</span>
<span class="severity convention">convention:</span>
<span class="message">Style/RescueModifier: Avoid using <code>rescue</code> in its modifier form.</span>
</div>

Expand All @@ -656,7 +667,7 @@ <h1 class="title">RuboCop Inspection Report</h1>

<div class="report">
<div class="meta">
<span class="location">Line #4</span>
<span class="location">Line #5</span>
<span class="severity convention">convention:</span>
<span class="message">Style/RegexpLiteral: Use <code>%r</code> around regular expression.</span>
</div>
Expand Down
1 change: 1 addition & 0 deletions spec/fixtures/html_formatter/project/app/models/book.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class Book < ActiveRecord::Base
def someMethod
foo = bar = baz
qux(quux.scan(/&amp;&lt;/))
Regexp.new(/\A<p>(.*)<\/p>\Z/m).match(full_document)[1] rescue full_document
end
end
17 changes: 13 additions & 4 deletions spec/rubocop/formatter/html_formatter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,19 @@
Dir.chdir(File.basename(project_path)) { example.run }
end

# Run without Style/EndOfLine as it gives different results on
# different platforms.
# Metrics/AbcSize is very strict, exclude it too
let(:options) { %w[--except Layout/EndOfLine,Metrics/AbcSize --format html --out] }
let(:enabled_cops) do
[
'Layout/EmptyLinesAroundAccessModifier', 'Layout/IndentationConsistency',
'Layout/IndentationWidth', 'Layout/LineLength', 'Lint/UselessAssignment',
'Naming/MethodName', 'Style/Documentation', 'Style/EmptyMethod',
'Style/FrozenStringLiteralComment', 'Style/RedundantRegexpArgument', 'Style/RegexpLiteral',
'Style/RescueModifier', 'Style/SymbolArray'
].join(',')
end

let(:options) do
['--only', enabled_cops, '--format', 'html', '--out']
end

let(:actual_html_path) do
path = File.expand_path('result.html')
Expand Down

0 comments on commit c0f5b35

Please sign in to comment.