Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Allow oddly-quoted (usually automatically-generated) gem names in gem…

…files and gemspecs
  • Loading branch information...
commit b5bf191b6565b2bdb31ab60daf6c17874fe8ce7a 1 parent 3b49d92
@laserlemon laserlemon authored
View
5 lib/gemnasium/parser/patterns.rb
@@ -2,6 +2,7 @@ module Gemnasium
module Parser
module Patterns
GEM_NAME = /[a-zA-Z0-9\-_]+/
+ QUOTED_GEM_NAME = /(?:(?<gq>["'])(?<name>#{GEM_NAME})\k<gq>|%q<(?<name>#{GEM_NAME})>)/
MATCHER = /(?:=|!=|>|<|>=|<=|~>)/
VERSION = /[0-9]+(?:\.[a-zA-Z0-9]+)*/
@@ -21,7 +22,7 @@ module Patterns
OPTIONS = /#{PAIR}(?:[ \t]*,[ \t]*#{PAIR})*/
COMMENT = /(#[^\n]*)?/
- GEM_CALL = /^[ \t]*gem\(?[ \t]*(?<q1>["'])(?<name>#{GEM_NAME})\k<q1>(?:[ \t]*,[ \t]*#{REQUIREMENT_LIST})?(?:[ \t]*,[ \t]*(?<opts>#{OPTIONS}))?[ \t]*\)?[ \t]*#{COMMENT}$/
+ GEM_CALL = /^[ \t]*gem\(?[ \t]*#{QUOTED_GEM_NAME}(?:[ \t]*,[ \t]*#{REQUIREMENT_LIST})?(?:[ \t]*,[ \t]*(?<opts>#{OPTIONS}))?[ \t]*\)?[ \t]*#{COMMENT}$/
SYMBOLS = /#{SYMBOL}([ \t]*,[ \t]*#{SYMBOL})*/
GROUP_CALL = /^(?<i1>[ \t]*)group\(?[ \t]*(?<grps>#{SYMBOLS})[ \t]*\)?[ \t]+do[ \t]*?\n(?<blk>[^\n]*?)\n^\k<i1>end[ \t]*$/m
@@ -32,7 +33,7 @@ module Patterns
GEMSPEC_CALL = /^[ \t]*gemspec(?:\(?[ \t]*(?<opts>#{OPTIONS}))?[ \t]*\)?[ \t]*$/
- ADD_DEPENDENCY_CALL = /^[ \t]*\w+\.add(?<type>_runtime|_development)?_dependency\(?[ \t]*(?<q1>["'])(?<name>#{GEM_NAME})\k<q1>(?:[ \t]*,[ \t]*#{REQUIREMENTS})?[ \t]*\)?[ \t]*#{COMMENT}$/
+ ADD_DEPENDENCY_CALL = /^[ \t]*\w+\.add(?<type>_runtime|_development)?_dependency\(?[ \t]*#{QUOTED_GEM_NAME}(?:[ \t]*,[ \t]*#{REQUIREMENTS})?[ \t]*\)?[ \t]*#{COMMENT}$/
def self.options(string)
{}.tap do |hash|
View
5 spec/gemnasium/parser/gemfile_spec.rb
@@ -248,4 +248,9 @@ def reset
dependency.name.should == "rake"
dependency.requirement.should == ">= 0.8.7"
end
+
+ it "parses oddly quoted gems" do
+ content(%(gem %q<rake>))
+ dependency.name.should == "rake"
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.