-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
don't parse nodes inside comment and raw tags
Co-Authored by Alex Coco <alex.coco@shopify.com>
- Loading branch information
1 parent
0b93182
commit 760961a
Showing
5 changed files
with
60 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# frozen_string_literal: true | ||
|
||
module Liquid | ||
class NonParsingBlock < Block | ||
def parse_body(body, tokens) | ||
if parse_context.depth >= MAX_DEPTH | ||
raise StackLevelError, "Nesting too deep" | ||
end | ||
parse_context.depth += 1 | ||
|
||
begin | ||
while token = tokens.shift | ||
tag_name_match = BlockBody::FullToken.match(token) | ||
|
||
return false if tag_name_match && tag_name_match[2] == block_delimiter | ||
end | ||
|
||
raise_tag_never_closed(block_name) | ||
ensure | ||
parse_context.depth -= 1 | ||
end | ||
|
||
false | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'test_helper' | ||
|
||
class NonParsingBlockTest < Minitest::Test | ||
include Liquid | ||
|
||
def test_comment_tag_does_not_parse_nodes_inside_a_comment | ||
template = Template.parse(<<~LIQUID.chomp, line_numbers: true) | ||
{% comment %} | ||
{% if true %} | ||
{% while true %} | ||
{% endcomment %} | ||
LIQUID | ||
end | ||
|
||
def test_error_line_number_is_correct | ||
template = Template.parse(<<~LIQUID.chomp, line_numbers: true) | ||
{% raw %}{% endraw %} | ||
{{ errors.standard_error }} | ||
LIQUID | ||
|
||
output = template.render('errors' => ErrorDrop.new) | ||
expected = <<~TEXT.chomp | ||
Liquid error (line 2): standard error | ||
TEXT | ||
|
||
assert_equal(expected, output) | ||
end | ||
end |