Skip to content

Commit

Permalink
Use Regexp#match? when MatchData is not used (Shopify#1165)
Browse files Browse the repository at this point in the history
* Use `Regexp#match?` when `MatchData` is not used

* Add `TargetRubyVersion: 2.4` to RuboCop config
  • Loading branch information
ashmaroli authored and shopmike committed Sep 19, 2019
1 parent ca207ed commit 2c14e0b
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Performance:
Enabled: true

AllCops:
TargetRubyVersion: 2.4
Exclude:
- 'vendor/bundle/**/*'

Expand Down
2 changes: 1 addition & 1 deletion lib/liquid/file_system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def read_template_file(template_path)
end

def full_path(template_path)
raise FileSystemError, "Illegal template name '#{template_path}'" unless template_path =~ %r{\A[^./][a-zA-Z0-9_/]+\z}
raise FileSystemError, "Illegal template name '#{template_path}'" unless %r{\A[^./][a-zA-Z0-9_/]+\z}.match?(template_path)

full_path = if template_path.include?('/')
File.join(root, File.dirname(template_path), @pattern % File.basename(template_path))
Expand Down
2 changes: 1 addition & 1 deletion lib/liquid/tags/raw.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def blank?
protected

def ensure_valid_markup(tag_name, markup, parse_context)
unless markup =~ Syntax
unless Syntax.match?(markup)
raise SyntaxError, parse_context.locale.t("errors.syntax.tag_unexpected_args", tag: tag_name)
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/liquid/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def self.to_number(obj)
when Numeric
obj
when String
obj.strip =~ /\A-?\d+\.\d+\z/ ? BigDecimal(obj) : obj.to_i
/\A-?\d+\.\d+\z/.match?(obj.strip) ? BigDecimal(obj) : obj.to_i
else
if obj.respond_to?(:to_number)
obj.to_number
Expand Down

0 comments on commit 2c14e0b

Please sign in to comment.