Skip to content

Commit 954e3b3

Browse files
Fix(strip_html): handle multiline comments
The `strip_html` filter was not correctly handling multiline HTML comments. This was due to the regex using the `m` flag instead of the `s` flag. The `m` flag only makes `^` and `$` match the start and end of lines, while the `s` flag makes `.` match any character, including newlines. This commit changes the regex flags from `m` to `s` for both `@html_blocks` and `@html_tags` to correctly handle multiline content. A doctest has been added to cover the failing case.
1 parent d1937e9 commit 954e3b3

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

.tool-versions

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
erlang 27.0
22
elixir 1.17.2
3+
ruby 3.3.0

lib/solid/standard_filter.ex

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,9 +1137,11 @@ defmodule Solid.StandardFilter do
11371137
Output
11381138
iex> Solid.StandardFilter.strip_html("Have <em>you</em> read <strong>Ulysses</strong>?")
11391139
"Have you read Ulysses?"
1140+
iex> Solid.StandardFilter.strip_html("<!-- foo bar \\n test -->test")
1141+
"test"
11401142
"""
1141-
@html_blocks ~r{(<script.*?</script>)|(<!--.*?-->)|(<style.*?</style>)}m
1142-
@html_tags ~r|<.*?>|m
1143+
@html_blocks ~r{(<script.*?</script>)|(<!--.*?-->)|(<style.*?</style>)}s
1144+
@html_tags ~r|<.*?>|s
11431145
@spec strip_html(iodata()) :: String.t()
11441146
def strip_html(iodata) do
11451147
iodata

test/solid/integration/scenarios/filter/input.liquid

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,3 +587,7 @@ sort_natural
587587
{{ (0..15) | sort_natural | join: ", " }}
588588
{{ 123 | sort_natural | join: ", " }}
589589
{{ fruits | sort_natural | join: ", " }}
590+
591+
strip_html
592+
593+
{{ "<!-- foo bar \\n test -->test" | strip_html }}

0 commit comments

Comments
 (0)