fix variable lookup parse timing out with missing closing bracket

This commit is contained in:
Michael Go
2023-02-01 19:52:30 -04:00
parent 22ded5f304
commit 2b40850e4a
2 changed files with 28 additions and 1 deletions
+1 -1
View File
@@ -41,7 +41,7 @@ module Liquid
AnyStartingTag = /#{TagStart}|#{VariableStart}/o
PartialTemplateParser = /#{TagStart}.*?#{TagEnd}|#{VariableStart}.*?#{VariableIncompleteEnd}/om
TemplateParser = /(#{PartialTemplateParser}|#{AnyStartingTag})/om
VariableParser = /\[(?:[^\[\]]+|\g<0>)*\]|#{VariableSegment}+\??/o
VariableParser = /\[(?>[^\[\]]+|\g<0>)*\]|#{VariableSegment}+\??/o
RAISE_EXCEPTION_LAMBDA = ->(_e) { raise }
+27
View File
@@ -1,6 +1,7 @@
# frozen_string_literal: true
require 'test_helper'
require 'timeout'
class VariableTest < Minitest::Test
include Liquid
@@ -169,4 +170,30 @@ class VariableTest < Minitest::Test
}
)
end
def test_variable_lookup_should_not_hang_with_invalid_syntax
Timeout.timeout(1) do
assert_template_result(
'bar',
"{{['foo'}}",
{
'foo' => 'bar',
},
error_mode: :lax,
)
end
very_long_key = "1234567890" * 100
Timeout.timeout(1) do
assert_template_result(
'bar',
"{{['#{very_long_key}'}}",
{
very_long_key => 'bar',
},
error_mode: :lax,
)
end
end
end