Disallow number and dash identifier prefixes

This commit is contained in:
Justin Li
2014-10-29 12:08:00 -04:00
parent a07e382617
commit dd5ee81089
4 changed files with 7 additions and 10 deletions

View File

@@ -13,7 +13,7 @@ module Liquid
'?'.freeze => :question,
'-'.freeze => :dash
}
IDENTIFIER = /[\w-]+\??/
IDENTIFIER = /[a-zA-Z_]+[\w-]*\??/
SINGLE_STRING_LITERAL = /'[^\']*'/
DOUBLE_STRING_LITERAL = /"[^\"]*"/
NUMBER_LITERAL = /-?\d+(\.\d+)?/

View File

@@ -12,7 +12,6 @@ module Liquid
#
class Variable
FilterParser = /(?:\s+|#{QuotedFragment}|#{ArgumentSeparator})+/o
EasyParse = /\A *(\w+(?:\.\w+)*) *\z/
attr_accessor :filters, :name, :warnings
attr_accessor :line_number
include ParserSwitching
@@ -53,13 +52,6 @@ module Liquid
end
def strict_parse(markup)
# Very simple valid cases
if markup =~ EasyParse
@name = Expression.parse($1)
@filters = []
return
end
@filters = []
p = Parser.new(markup)

View File

@@ -32,7 +32,10 @@ class LexerUnitTest < Minitest::Test
def test_fancy_identifiers
tokens = Lexer.new('hi five?').tokenize
assert_equal [[:id,'hi'], [:id, 'five?'], [:end_of_string]], tokens
assert_equal [[:id, 'hi'], [:id, 'five?'], [:end_of_string]], tokens
tokens = Lexer.new('2foo').tokenize
assert_equal [[:number, '2'], [:id, 'foo'], [:end_of_string]], tokens
end
def test_whitespace

View File

@@ -108,6 +108,8 @@ class VariableUnitTest < Minitest::Test
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