diff --git a/lib/liquid/tokenizer.rb b/lib/liquid/tokenizer.rb index 1b3984cab..740f85999 100644 --- a/lib/liquid/tokenizer.rb +++ b/lib/liquid/tokenizer.rb @@ -5,7 +5,7 @@ class Tokenizer attr_reader :line_number, :for_liquid_tag def initialize(source, line_numbers = false, line_number: nil, for_liquid_tag: false) - @source = source + @source = source.to_s.to_str @line_number = line_number || (line_numbers ? 1 : nil) @for_liquid_tag = for_liquid_tag @offset = 0 diff --git a/test/unit/tokenizer_unit_test.rb b/test/unit/tokenizer_unit_test.rb index 6e8557242..5e0496e68 100644 --- a/test/unit/tokenizer_unit_test.rb +++ b/test/unit/tokenizer_unit_test.rb @@ -30,6 +30,10 @@ def test_calculate_line_numbers_per_token_with_profiling assert_equal([1, 1, 3], tokenize_line_numbers(" {{\n funk \n}} ")) end + def test_tokenize_with_nil_source_returns_empty_array + assert_equal([], tokenize(nil)) + end + private def new_tokenizer(source, parse_context: Liquid::ParseContext.new, start_line_number: nil)