Skip to content

Commit 679625f

Browse files
committed
Fixed Liquid provider to sanitize HTML content
Ensures rendering of Liquid templates are sanitized before final output is generated. This also improves consistency across the application (especially when rendering screens for devices (which has had this capability for a while). Milestone: patch
1 parent f75cb6c commit 679625f

File tree

4 files changed

+26
-8
lines changed

4 files changed

+26
-8
lines changed

config/providers/liquid.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
default = TRMNL::Liquid.new { |environment| environment.error_mode = :strict }
88

99
renderer = lambda do |template, data, environment: default|
10-
Liquid::Template.parse(template, environment:).render data
10+
slice["aspects.sanitizer"].call Liquid::Template.parse(template, environment:).render(data)
1111
end
1212

1313
register :default, renderer

spec/app/aspects/extensions/renderers/image_spec.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
it "renders template with single URI" do
2121
expect(renderer.call(extension, context:)).to be_success(
2222
Terminus::Aspects::Extensions::Capsule[
23-
content: %(<img src="https://test.io/test.png" alt="Image">)
23+
content: <<~CONTENT.strip
24+
<html><head></head><body><img src="https://test.io/test.png" alt="Image"></body></html>
25+
CONTENT
2426
]
2527
)
2628
end
@@ -35,9 +37,10 @@
3537

3638
expect(renderer.call(extension, context:)).to be_success(
3739
Terminus::Aspects::Extensions::Capsule[
38-
content: <<~CONTENT
39-
<img src="https://test.io/one.png" alt="Image">
40+
content: <<~CONTENT.strip
41+
<html><head></head><body><img src="https://test.io/one.png" alt="Image">
4042
<img src="https://test.io/two.png" alt="Image">
43+
</body></html>
4144
CONTENT
4245
]
4346
)

spec/app/aspects/extensions/renderers/poll_spec.rb

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,13 @@
4242

4343
expect(renderer.call(extension, context:)).to be_success(
4444
Terminus::Aspects::Extensions::Capsule[
45-
content: %(<h1>Test Label</h1>\n\n <p>Test: A test.</p>\n\n)
45+
content: <<~CONTENT.strip
46+
<html><head></head><body><h1>Test Label</h1>
47+
48+
<p>Test: A test.</p>
49+
50+
</body></html>
51+
CONTENT
4652
]
4753
)
4854
end
@@ -67,11 +73,12 @@
6773
end
6874

6975
it "answers render template and captures errors" do
70-
html = <<~CONTENT
71-
<h1>Test Label</h1>
76+
html = <<~CONTENT.strip
77+
<html><head></head><body><h1>Test Label</h1>
7278
<p>Test</p>
7379
7480
<p>Test</p>
81+
</body></html>
7582
CONTENT
7683

7784
expect(renderer.call(extension, context:)).to be_failure(

spec/app/aspects/extensions/renderers/static_spec.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,15 @@
3030

3131
expect(renderer.call(extension, context:)).to be_success(
3232
Terminus::Aspects::Extensions::Capsule[
33-
content: %(<h1>Days</h1>\n\n <p>One</p>\n\n <p>Two</p>\n\n)
33+
content: <<~CONTENT.strip
34+
<html><head></head><body><h1>Days</h1>
35+
36+
<p>One</p>
37+
38+
<p>Two</p>
39+
40+
</body></html>
41+
CONTENT
3442
]
3543
)
3644
end

0 commit comments

Comments
 (0)