Use start and end of string rather than line matching in regexes.

This commit is contained in:
Dylan Thacker-Smith
2014-03-13 17:56:42 -04:00
parent 3efa8e8762
commit 503d924274
10 changed files with 21 additions and 21 deletions
+1 -1
View File
@@ -13,7 +13,7 @@ class LiquidServlet < WEBrick::HTTPServlet::AbstractServlet
def handle(type, req, res) def handle(type, req, res)
@request, @response = req, res @request, @response = req, res
@request.path_info =~ /(\w+)$/ @request.path_info =~ /(\w+)\z/
@action = $1 || 'index' @action = $1 || 'index'
@assigns = send(@action) if respond_to?(@action) @assigns = send(@action) if respond_to?(@action)
+1 -1
View File
@@ -36,7 +36,7 @@ module Liquid
StrictQuotedFragment = /"[^"]+"|'[^']+'|[^\s|:,]+/ StrictQuotedFragment = /"[^"]+"|'[^']+'|[^\s|:,]+/
FirstFilterArgument = /#{FilterArgumentSeparator}(?:#{StrictQuotedFragment})/o FirstFilterArgument = /#{FilterArgumentSeparator}(?:#{StrictQuotedFragment})/o
OtherFilterArgument = /#{ArgumentSeparator}(?:#{StrictQuotedFragment})/o OtherFilterArgument = /#{ArgumentSeparator}(?:#{StrictQuotedFragment})/o
SpacelessFilter = /^(?:'[^']+'|"[^"]+"|[^'"])*#{FilterSeparator}(?:#{StrictQuotedFragment})(?:#{FirstFilterArgument}(?:#{OtherFilterArgument})*)?/o SpacelessFilter = /\A(?:'[^']+'|"[^"]+"|[^'"])*#{FilterSeparator}(?:#{StrictQuotedFragment})(?:#{FirstFilterArgument}(?:#{OtherFilterArgument})*)?/o
Expression = /(?:#{QuotedFragment}(?:#{SpacelessFilter})*)/o Expression = /(?:#{QuotedFragment}(?:#{SpacelessFilter})*)/o
TagAttributes = /(\w+)\s*\:\s*(#{QuotedFragment})/o TagAttributes = /(\w+)\s*\:\s*(#{QuotedFragment})/o
AnyStartingTag = /\{\{|\{\%/ AnyStartingTag = /\{\{|\{\%/
+4 -4
View File
@@ -1,9 +1,9 @@
module Liquid module Liquid
class Block < Tag class Block < Tag
IsTag = /^#{TagStart}/o IsTag = /\A#{TagStart}/o
IsVariable = /^#{VariableStart}/o IsVariable = /\A#{VariableStart}/o
FullToken = /^#{TagStart}\s*(\w+)\s*(.*)?#{TagEnd}$/o FullToken = /\A#{TagStart}\s*(\w+)\s*(.*)?#{TagEnd}\z/o
ContentOfVariable = /^#{VariableStart}(.*)#{VariableEnd}$/o ContentOfVariable = /\A#{VariableStart}(.*)#{VariableEnd}\z/o
def blank? def blank?
@blank || false @blank || false
+6 -6
View File
@@ -171,15 +171,15 @@ module Liquid
LITERALS[key] LITERALS[key]
else else
case key case key
when /^'(.*)'$/ # Single quoted strings when /\A'(.*)'\z/ # Single quoted strings
$1 $1
when /^"(.*)"$/ # Double quoted strings when /\A"(.*)"\z/ # Double quoted strings
$1 $1
when /^(-?\d+)$/ # Integer and floats when /\A(-?\d+)\z/ # Integer and floats
$1.to_i $1.to_i
when /^\((\S+)\.\.(\S+)\)$/ # Ranges when /\A\((\S+)\.\.(\S+)\)\z/ # Ranges
(resolve($1).to_i..resolve($2).to_i) (resolve($1).to_i..resolve($2).to_i)
when /^(-?\d[\d\.]+)$/ # Floats when /\A(-?\d[\d\.]+)\z/ # Floats
$1.to_f $1.to_f
else else
variable(key) variable(key)
@@ -218,7 +218,7 @@ module Liquid
# assert_equal 'tobi', @context['hash["name"]'] # assert_equal 'tobi', @context['hash["name"]']
def variable(markup) def variable(markup)
parts = markup.scan(VariableParser) parts = markup.scan(VariableParser)
square_bracketed = /^\[(.*)\]$/ square_bracketed = /\A\[(.*)\]\z/
first_part = parts.shift first_part = parts.shift
+2 -2
View File
@@ -57,7 +57,7 @@ module Liquid
end end
def full_path(template_path) def full_path(template_path)
raise FileSystemError, "Illegal template name '#{template_path}'" unless template_path =~ /^[^.\/][a-zA-Z0-9_\/]+$/ raise FileSystemError, "Illegal template name '#{template_path}'" unless template_path =~ /\A[^.\/][a-zA-Z0-9_\/]+\z/
full_path = if template_path.include?('/') full_path = if template_path.include?('/')
File.join(root, File.dirname(template_path), @pattern % File.basename(template_path)) File.join(root, File.dirname(template_path), @pattern % File.basename(template_path))
@@ -65,7 +65,7 @@ module Liquid
File.join(root, @pattern % template_path) File.join(root, @pattern % template_path)
end end
raise FileSystemError, "Illegal template path '#{File.expand_path(full_path)}'" unless File.expand_path(full_path) =~ /^#{File.expand_path(root)}/ raise FileSystemError, "Illegal template path '#{File.expand_path(full_path)}'" unless File.expand_path(full_path) =~ /\A#{File.expand_path(root)}/
full_path full_path
end end
+2 -2
View File
@@ -190,7 +190,7 @@ module Liquid
return input.to_s return input.to_s
end end
if ((input.is_a?(String) && !/^\d+$/.match(input.to_s).nil?) || input.is_a?(Integer)) && input.to_i > 0 if ((input.is_a?(String) && !/\A\d+\z/.match(input.to_s).nil?) || input.is_a?(Integer)) && input.to_i > 0
input = Time.at(input.to_i) input = Time.at(input.to_i)
end end
@@ -281,7 +281,7 @@ module Liquid
when Numeric when Numeric
obj obj
when String when String
(obj.strip =~ /^\d+\.\d+$/) ? BigDecimal.new(obj) : obj.to_i (obj.strip =~ /\A\d+\.\d+\z/) ? BigDecimal.new(obj) : obj.to_i
else else
0 0
end end
+2 -2
View File
@@ -12,8 +12,8 @@ module Liquid
# <div class="green"> Item five</div> # <div class="green"> Item five</div>
# #
class Cycle < Tag class Cycle < Tag
SimpleSyntax = /^#{QuotedFragment}+/o SimpleSyntax = /\A#{QuotedFragment}+/o
NamedSyntax = /^(#{QuotedFragment})\s*\:\s*(.*)/o NamedSyntax = /\A(#{QuotedFragment})\s*\:\s*(.*)/o
def initialize(tag_name, markup, tokens) def initialize(tag_name, markup, tokens)
case markup case markup
+1 -1
View File
@@ -1,6 +1,6 @@
module Liquid module Liquid
class Raw < Block class Raw < Block
FullTokenPossiblyInvalid = /^(.*)#{TagStart}\s*(\w+)\s*(.*)?#{TagEnd}$/o FullTokenPossiblyInvalid = /\A(.*)#{TagStart}\s*(\w+)\s*(.*)?#{TagEnd}\z/o
def parse(tokens) def parse(tokens)
@nodelist ||= [] @nodelist ||= []
+1 -1
View File
@@ -12,7 +12,7 @@ module Liquid
# #
class Variable class Variable
FilterParser = /(?:#{FilterSeparator}|(?:\s*(?:#{QuotedFragment}|#{ArgumentSeparator})\s*)+)/o FilterParser = /(?:#{FilterSeparator}|(?:\s*(?:#{QuotedFragment}|#{ArgumentSeparator})\s*)+)/o
EasyParse = /^ *(\w+(?:\.\w+)*) *$/ EasyParse = /\A *(\w+(?:\.\w+)*) *\z/
attr_accessor :filters, :name, :warnings attr_accessor :filters, :name, :warnings
def initialize(markup, options = {}) def initialize(markup, options = {})
+1 -1
View File
@@ -54,7 +54,7 @@ module ShopFilter
def product_img_url(url, style = 'small') def product_img_url(url, style = 'small')
unless url =~ /^products\/([\w\-\_]+)\.(\w{2,4})/ unless url =~ /\Aproducts\/([\w\-\_]+)\.(\w{2,4})/
raise ArgumentError, 'filter "size" can only be called on product images' raise ArgumentError, 'filter "size" can only be called on product images'
end end