mirror of
https://github.com/Shopify/liquid.git
synced 2026-10-03 00:55:11 -07:00
Revert "Merge pull request #478 from Shopify/numbers-in-identifiers"
This reverts commit263e90e772, reversing changes made to4dc682313f.
This commit is contained in:
+1
-1
@@ -13,7 +13,7 @@ module Liquid
|
|||||||
'?'.freeze => :question,
|
'?'.freeze => :question,
|
||||||
'-'.freeze => :dash
|
'-'.freeze => :dash
|
||||||
}
|
}
|
||||||
IDENTIFIER = /[a-zA-Z_][\w-]*\??/
|
IDENTIFIER = /\w+/
|
||||||
SINGLE_STRING_LITERAL = /'[^\']*'/
|
SINGLE_STRING_LITERAL = /'[^\']*'/
|
||||||
DOUBLE_STRING_LITERAL = /"[^\"]*"/
|
DOUBLE_STRING_LITERAL = /"[^\"]*"/
|
||||||
NUMBER_LITERAL = /-?\d+(\.\d+)?/
|
NUMBER_LITERAL = /-?\d+(\.\d+)?/
|
||||||
|
|||||||
@@ -75,6 +75,13 @@ module Liquid
|
|||||||
|
|
||||||
def variable_signature
|
def variable_signature
|
||||||
str = consume(:id)
|
str = consume(:id)
|
||||||
|
while consume?(:dash)
|
||||||
|
str << "-".freeze
|
||||||
|
str << consume(:id)
|
||||||
|
end
|
||||||
|
if consume?(:question)
|
||||||
|
str << "?".freeze
|
||||||
|
end
|
||||||
if look(:open_square)
|
if look(:open_square)
|
||||||
str << consume
|
str << consume
|
||||||
str << expression
|
str << expression
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ module Liquid
|
|||||||
#
|
#
|
||||||
class Variable
|
class Variable
|
||||||
FilterParser = /(?:\s+|#{QuotedFragment}|#{ArgumentSeparator})+/o
|
FilterParser = /(?:\s+|#{QuotedFragment}|#{ArgumentSeparator})+/o
|
||||||
|
EasyParse = /\A *(\w+(?:\.\w+)*) *\z/
|
||||||
attr_accessor :filters, :name, :warnings
|
attr_accessor :filters, :name, :warnings
|
||||||
attr_accessor :line_number
|
attr_accessor :line_number
|
||||||
include ParserSwitching
|
include ParserSwitching
|
||||||
@@ -52,6 +53,13 @@ module Liquid
|
|||||||
end
|
end
|
||||||
|
|
||||||
def strict_parse(markup)
|
def strict_parse(markup)
|
||||||
|
# Very simple valid cases
|
||||||
|
if markup =~ EasyParse
|
||||||
|
@name = Expression.parse($1)
|
||||||
|
@filters = []
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
@filters = []
|
@filters = []
|
||||||
p = Parser.new(markup)
|
p = Parser.new(markup)
|
||||||
|
|
||||||
|
|||||||
@@ -32,10 +32,7 @@ class LexerUnitTest < Minitest::Test
|
|||||||
|
|
||||||
def test_fancy_identifiers
|
def test_fancy_identifiers
|
||||||
tokens = Lexer.new('hi five?').tokenize
|
tokens = Lexer.new('hi five?').tokenize
|
||||||
assert_equal [[:id, 'hi'], [:id, 'five?'], [:end_of_string]], tokens
|
assert_equal [[:id,'hi'], [:id, 'five'], [:question, '?'], [:end_of_string]], tokens
|
||||||
|
|
||||||
tokens = Lexer.new('2foo').tokenize
|
|
||||||
assert_equal [[:number, '2'], [:id, 'foo'], [:end_of_string]], tokens
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_whitespace
|
def test_whitespace
|
||||||
|
|||||||
@@ -102,17 +102,6 @@ class VariableUnitTest < Minitest::Test
|
|||||||
assert_equal 1000.01, var.name
|
assert_equal 1000.01, var.name
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_dashes
|
|
||||||
assert_equal VariableLookup.new('foo-bar'), Variable.new('foo-bar').name
|
|
||||||
assert_equal VariableLookup.new('foo-bar-2'), Variable.new('foo-bar-2').name
|
|
||||||
|
|
||||||
with_error_mode :strict do
|
|
||||||
assert_raises(Liquid::SyntaxError) { Variable.new('foo - bar') }
|
|
||||||
assert_raises(Liquid::SyntaxError) { Variable.new('-foo') }
|
|
||||||
assert_raises(Liquid::SyntaxError) { Variable.new('2foo') }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_string_with_special_chars
|
def test_string_with_special_chars
|
||||||
var = Variable.new(%| 'hello! $!@.;"ddasd" ' |)
|
var = Variable.new(%| 'hello! $!@.;"ddasd" ' |)
|
||||||
assert_equal 'hello! $!@.;"ddasd" ', var.name
|
assert_equal 'hello! $!@.;"ddasd" ', var.name
|
||||||
|
|||||||
Reference in New Issue
Block a user