diff --git a/graphql.gemspec b/graphql.gemspec index abb03cd849..30bb67c69a 100644 --- a/graphql.gemspec +++ b/graphql.gemspec @@ -37,6 +37,7 @@ Gem::Specification.new do |s| s.add_development_dependency "minitest" s.add_development_dependency "minitest-focus" + s.add_development_dependency "minitest-mock" s.add_development_dependency "minitest-reporters" s.add_development_dependency "ostruct" s.add_development_dependency "rake" diff --git a/lib/graphql/language.rb b/lib/graphql/language.rb index b230d340ab..1f40cbb04d 100644 --- a/lib/graphql/language.rb +++ b/lib/graphql/language.rb @@ -77,7 +77,10 @@ def self.escape_single_quoted_newlines(query_str) new_query_str || query_str end + LEADING_REGEX = Regexp.union(" ", *Lexer::Punctuation.constants.map { |const| Lexer::Punctuation.const_get(const) }) + INVALID_NUMBER_FOLLOWED_BY_NAME_REGEXP = %r{ + (?#{LEADING_REGEX}) ( ((?#{Lexer::INT_REGEXP}(#{Lexer::FLOAT_EXP_REGEXP})?)(?#{Lexer::IDENTIFIER_REGEXP})#{Lexer::IGNORE_REGEXP}:) | @@ -88,7 +91,7 @@ def self.escape_single_quoted_newlines(query_str) def self.add_space_between_numbers_and_names(query_str) if query_str.match?(INVALID_NUMBER_FOLLOWED_BY_NAME_REGEXP) - query_str.gsub(INVALID_NUMBER_FOLLOWED_BY_NAME_REGEXP, "\\k \\k:") + query_str.gsub(INVALID_NUMBER_FOLLOWED_BY_NAME_REGEXP, "\\k\\k \\k:") else query_str end diff --git a/spec/graphql/language/parser_spec.rb b/spec/graphql/language/parser_spec.rb index 1308f0a5f8..9f5a366c15 100644 --- a/spec/graphql/language/parser_spec.rb +++ b/spec/graphql/language/parser_spec.rb @@ -267,6 +267,7 @@ "{ a(b: 123e5 ) }" => nil, "{ a(b: 12.3e5) }" => nil, "{ a(b: 12.3e5 ) }" => nil, + "query($cursor1_something: Int) { f(a: $cursor1_something) }" => nil, "query($obj: Input = { a: 1e5b: 2c: 3e-1}) { t }" => "query($obj: Input = { a: 1e5 b: 2 c: 3e-1}) { t }" , } diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index cd5dd98d88..0e402325bb 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -51,6 +51,7 @@ require "minitest/autorun" require "minitest/focus" require "minitest/reporters" +require "minitest/mock" require "graphql/batch" running_in_rubymine = ENV["RM_INFO"]