Skip to content

Commit 9bb1ddd

Browse files
authored
Merge pull request #81 from easolhq/fix-html-validator-on-liquid-variable-for-tag
Allow html elements to be set by liquid variables
2 parents 464f76b + ed1b585 commit 9bb1ddd

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

lib/canvas/validators/html.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ def extracted_html
3131
end
3232

3333
# We want to strip out the liquid tags and replace them with the
34-
# same number of empty space characters, so that the linter
35-
# reports the correct character number.
34+
# same number of characters, so that the linter reports the
35+
# correct character number.
3636
def strip_out_liquid(html)
37-
html.gsub(LIQUID_TAG_OR_VARIABLE) { |tag| " " * tag.size }
37+
html.gsub(LIQUID_TAG_OR_VARIABLE) { |tag| "x" * tag.size }
3838
end
3939

4040
# We want to strip out the front matter and replace it

lib/canvas/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module Canvas
4-
VERSION = "4.15.0"
4+
VERSION = "4.16.0"
55
end

spec/lib/canvas/checks/valid_html_check_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
message = <<~MESSAGE.chop
1818
Invalid HTML: blocks/hero/block.liquid - \n
1919
14:16: ERROR: Start tag of nonvoid HTML element ends with '/>', use '>'.
20-
<h1> <foo/>
20+
<h1>xxxxxxxxxxx<foo/>
2121
^
2222
MESSAGE
2323

spec/lib/canvas/validators/html_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,13 @@
4444

4545
expect(Canvas::Validator::Html.new(html).validate).to be_truthy
4646
end
47+
48+
it "strips out liquid" do
49+
html = <<-LIQUID
50+
<{{ tag | default: 'div' }}>This is valid html</{{ tag | default: 'div' }}>
51+
LIQUID
52+
53+
expect(Canvas::Validator::Html.new(html).validate).to be_truthy
54+
end
4755
end
4856
end

0 commit comments

Comments
 (0)