Commit cbd70dcf authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch 'exclude_html_entities_from_haml_lint' into 'master'

Exclude html entities from haml lint

Closes #33780

See merge request gitlab-org/gitlab!29847
parents e42010c7 ff28edb8
This diff is collapsed.
---
title: Exclude html entities from haml lint
merge_request: 29847
author: Lee Tickett
type: fixed
......@@ -51,6 +51,7 @@ module HamlLint
attributes = node.attributes_source.map(&:last)
attributes.each { |attribute| text = text.gsub(attribute, '') }
text = strip_html_entities(text)
text.strip
end
......@@ -77,7 +78,12 @@ module HamlLint
def text_node?(node)
return false unless plain_node?(node)
!node.text.empty?
text = strip_html_entities(node.text)
!text.empty?
end
def strip_html_entities(text)
text.gsub(/&([a-z0-9]+|#[0-9]{1,6}|#x[0-9a-f]{1,6});/i, "")
end
end
end
......
......@@ -53,4 +53,42 @@ describe HamlLint::Linter::NoPlainNodes do
it { is_expected.to report_lint count: 3 }
end
context 'does not report when a html entity' do
let(:haml) { '%tag  ' }
it { is_expected.not_to report_lint }
end
context 'does report when something that looks like a html entity' do
let(:haml) { '%tag &some text;' }
it { is_expected.to report_lint }
end
context 'does not report multiline when one or more html entities' do
%w( > © »).each do |elem|
let(:haml) { <<-HAML }
%tag
#{elem}
HAML
it elem do
is_expected.not_to report_lint
end
end
end
context 'does report multiline when one or more html entities amidst plain text' do
%w(&nbsp;Test Test&gt; &#x000A9;Hello &nbsp;Hello&#187;).each do |elem|
let(:haml) { <<-HAML }
%tag
#{elem}
HAML
it elem do
is_expected.to report_lint
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment