Skip to content

Commit

Permalink
allow extra string after raw tag delimiter
Browse files Browse the repository at this point in the history
  • Loading branch information
ggmichaelgo committed Sep 7, 2023
1 parent 8f11a88 commit 18c75f5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
11 changes: 10 additions & 1 deletion ext/liquid_c/raw.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ static bool match_full_token_possibly_invalid(token_t *token, struct full_token_
const char *curr_delimiter_start;
long curr_delimiter_len = 0;

bool is_last_char_whitespace = true;

for (long i = len - 3; i > 1; i--) {
char c = str[i];

Expand All @@ -35,12 +37,19 @@ static bool match_full_token_possibly_invalid(token_t *token, struct full_token_

if (is_word_char(c)) {
curr_delimiter_start = str + i;
curr_delimiter_len++;

if (is_last_char_whitespace) {
curr_delimiter_len = 1;
} else {
curr_delimiter_len++;
}
} else if (!is_word_char(c) && !is_whitespace) {
curr_delimiter_start = NULL;
curr_delimiter_len = 0;
}

is_last_char_whitespace = is_whitespace;

if (curr_delimiter_len > 0) {
if (
(str[i - 1] == '%' && str[i - 2] == '{') ||
Expand Down
10 changes: 10 additions & 0 deletions test/unit/raw_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ def test_derived_class
end
end

def test_allows_extra_string_after_tag_delimiter
output = Liquid::Template.parse("{% raw %}message{% endraw this_is_allowed %}").render
assert_equal("message", output)

output = Liquid::Template.parse("{% raw %}message{% endraw r%}").render
assert_equal("message", output)
end

def test_ignores_incomplete_tag_delimter
output = Liquid::Template.parse("{% raw %}{% endraw {% endraw %}").render
assert_equal("{% endraw ", output)
Expand All @@ -55,6 +63,7 @@ def test_does_not_allow_nbsp_in_tag_delimiter
Liquid::Template.parse("{% raw %}body{% endraw\u00A0 %}")
Liquid::Template.parse("{% raw %}body{% endraw \u00A0 %}")
Liquid::Template.parse("{% raw %}body{% endraw \u00A0 endraw %}")
Liquid::Template.parse("{% raw %}body{% endraw\u00A0endraw %}")

[
"{%\u00A0endraw%}",
Expand All @@ -63,6 +72,7 @@ def test_does_not_allow_nbsp_in_tag_delimiter
"{% \u00A0 endraw%}",
"{%\u00A0endraw\u00A0%}",
"{% - endraw %}",
"{% endnot endraw %}",
].each do |bad_delimiter|
exception = assert_raises(
Liquid::SyntaxError,
Expand Down

0 comments on commit 18c75f5

Please sign in to comment.