Skip to content

Commit

Permalink
Merge pull request #1776 from Shopify/refactor/invalid-encoding-error
Browse files Browse the repository at this point in the history
add new TemplateEncodingError
  • Loading branch information
ggmichaelgo committed Jan 12, 2024
2 parents cf76c0b + 7b25b77 commit 9b38a15
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
31 changes: 16 additions & 15 deletions lib/liquid/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,20 @@ def message_prefix
end
end

ArgumentError = Class.new(Error)
ContextError = Class.new(Error)
FileSystemError = Class.new(Error)
StandardError = Class.new(Error)
SyntaxError = Class.new(Error)
StackLevelError = Class.new(Error)
MemoryError = Class.new(Error)
ZeroDivisionError = Class.new(Error)
FloatDomainError = Class.new(Error)
UndefinedVariable = Class.new(Error)
UndefinedDropMethod = Class.new(Error)
UndefinedFilter = Class.new(Error)
MethodOverrideError = Class.new(Error)
DisabledError = Class.new(Error)
InternalError = Class.new(Error)
ArgumentError = Class.new(Error)
ContextError = Class.new(Error)
FileSystemError = Class.new(Error)
StandardError = Class.new(Error)
SyntaxError = Class.new(Error)
StackLevelError = Class.new(Error)
MemoryError = Class.new(Error)
ZeroDivisionError = Class.new(Error)
FloatDomainError = Class.new(Error)
UndefinedVariable = Class.new(Error)
UndefinedDropMethod = Class.new(Error)
UndefinedFilter = Class.new(Error)
MethodOverrideError = Class.new(Error)
DisabledError = Class.new(Error)
InternalError = Class.new(Error)
TemplateEncodingError = Class.new(Error)
end
2 changes: 1 addition & 1 deletion lib/liquid/template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def parse(source, options = {})
source = source.to_s.to_str

unless source.valid_encoding?
raise SyntaxError, parse_context.locale.t("errors.syntax.invalid_template_encoding")
raise TemplateEncodingError, parse_context.locale.t("errors.syntax.invalid_template_encoding")
end

tokenizer = parse_context.new_tokenizer(source, start_line_number: @line_numbers && 1)
Expand Down
4 changes: 2 additions & 2 deletions test/integration/template_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -339,15 +339,15 @@ def to_s
end

def test_raises_error_with_invalid_utf8
e = assert_raises(SyntaxError) do
e = assert_raises(TemplateEncodingError) do
Template.parse(<<~LIQUID)
{% comment %}
\xC0
{% endcomment %}
LIQUID
end

assert_equal('Liquid syntax error: Invalid template encoding', e.message)
assert_equal('Liquid error: Invalid template encoding', e.message)
end

def test_allows_non_string_values_as_source
Expand Down

0 comments on commit 9b38a15

Please sign in to comment.