webmock 3.23.1 → 3.26.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4cfe9b7372b311f25b6b531efc50e11297e19cb325306132b889bf2d67ab3fec
4
- data.tar.gz: 4448d921dc29e08024392f7fe0c8ab5a832920a6e749801e1ca2257a1c050e0b
3
+ metadata.gz: d61b9a1ba2457ef06a173ec71523bedaaecdac935b59611abeff105679da7cb3
4
+ data.tar.gz: 1d78e1c3b493bd1fc2af0961a6bebae5a273e1937b6cad6aaa7ef501e4b70778
5
5
  SHA512:
6
- metadata.gz: b6afe5a627d5c3c1498e5b4f35d07f9118977af57f4b7915b04bdeb67f2eb676bbbf5bfc28a895681c6635fe74d736d9a83d50916c2f80b1adb4b68d455de283
7
- data.tar.gz: 8843478e3cbcd78b3e4cc6d6a09c757ff02328549ea37768f23d721adb3721ab0daf49a000fcc8fa600382964538d6bc5aec7a6d1fdde4668a608b3b2b6fda08
6
+ metadata.gz: 4e56c8868b81ac1465e6b28b96041f9ea0a3cda7ef3728d0bc6715215d84baa44af5b5e1f4ba48597f34e6fd2e6f00f86cb5d61c194fb2eebd0a58caf92f615b
7
+ data.tar.gz: ea6072e9d1dbba86925558f31e10df790c5979f470806b92be7cfa483d47b1158ba55b1453981d696751ca2b2c98a1847f50cb635779a7eef7e7a377598777b4
data/CHANGELOG.md CHANGED
@@ -1,5 +1,69 @@
1
1
  # Changelog
2
2
 
3
+ # 3.26.2
4
+
5
+ * Add support to parse http/2 request on curb adapter
6
+
7
+ Thanks to [Christoph Rieß](https://github.com/criess)
8
+
9
+ * CurbAdapter alias `code` from `response_code`
10
+
11
+ Thanks to [Christoph Rieß](https://github.com/criess)
12
+
13
+ * Add HTTP.rb v6.0.0 compatibility to http_rb adapter
14
+
15
+ Thanks to [Erik Berlin](https://github.com/sferik)
16
+
17
+ # 3.26.1
18
+
19
+ * Fix compatibility with recent async-http versions
20
+
21
+ Thanks to [Mikhail Doronin](https://github.com/misdoro)
22
+
23
+ # 3.26.0
24
+
25
+ * Support Addressable::URI in request patterns
26
+
27
+ Thanks to [Alexey Zapparov](https://github.com/ixti)
28
+
29
+ # 3.25.2
30
+
31
+ * Return support for `em_http_request`
32
+
33
+ Thanks to [Oleg](https://github.com/Koilanetroc)
34
+
35
+ # 3.25.1
36
+
37
+ * Fix FrozenError in Typhoeus streaming response body
38
+
39
+ Thanks to [Patrick Jaberg](https://github.com/patrickjaberg)
40
+
41
+ # 3.25.0
42
+
43
+ * Resolve net-http adapter deprecation Ruby 3.4
44
+
45
+ Thanks to [Earlopain](https://github.com/Earlopain)
46
+
47
+ # 3.24.0
48
+
49
+ * Ignore parsing errors when parsing invalid JSON or XML body to match against body pattern #1066
50
+
51
+ Thanks to [Christian Schmidt](https://github.com/c960657)
52
+
53
+ * Added support for mocked HTTP::Connection#finished_request? method #1065
54
+
55
+ Thanks to [Christian Schmidt](https://github.com/c960657)
56
+
57
+ * Detect if Patron is loaded by checking if Patron::Session constant is defined #1068
58
+
59
+ Thanks to [Rodrigo Argumedo](https://github.com/rodrigoargumedo)
60
+
61
+ * Raising an ArgumentError when uri is passed as a Pathname object to stub_request or request expectation declaration.
62
+
63
+ * Dropped support for em-http-request on Ruby 3.4. The current version of em-http-request (1.1.7) is incompatible with Ruby 3.4 due to an unresolved issue (https://github.com/igrigorik/em-http-request/issues/365). Support for em-http-request will be re-enabled once the compatibility issue is resolved.
64
+
65
+ Thanks to [Christian Schmidt](https://github.com/c960657)
66
+
3
67
  # 3.23.1
4
68
 
5
69
  * Added support for async-http version >= 0.65.0 [PR](https://github.com/bblimke/webmock/pull/1056)
data/README.md CHANGED
@@ -44,6 +44,8 @@ Supported Ruby Interpreters
44
44
  * MRI 3.1
45
45
  * MRI 3.2
46
46
  * MRI 3.3
47
+ * MRI 3.4
48
+ * MRI 4.0
47
49
  * JRuby
48
50
 
49
51
  ## Installation
@@ -1204,6 +1206,13 @@ People who submitted patches and new features or suggested improvements. Many th
1204
1206
  * Gio Lodi
1205
1207
  * Ryan Brooks
1206
1208
  * Jacob Frautschi
1209
+ * Christian Schmidt
1210
+ * Rodrigo Argumedo
1211
+ * Patrick Jaberg
1212
+ * Oleg
1213
+ * Mikhail Doronin
1214
+ * Christoph Rieß
1215
+ * Erik Berlin
1207
1216
 
1208
1217
  For a full list of contributors you can visit the
1209
1218
  [contributors](https://github.com/bblimke/webmock/contributors) page.
@@ -35,9 +35,9 @@ if defined?(Async::HTTP)
35
35
  class WebMockClientWrapper < Client
36
36
  def initialize(
37
37
  endpoint,
38
- protocol = endpoint.protocol,
39
- scheme = endpoint.scheme,
40
- authority = endpoint.authority,
38
+ protocol: endpoint.protocol,
39
+ scheme: endpoint.scheme,
40
+ authority: endpoint.authority,
41
41
  **options
42
42
  )
43
43
  webmock_endpoint = WebMockEndpoint.new(scheme, authority, protocol)
@@ -45,6 +45,7 @@ if defined?(Async::HTTP)
45
45
  @network_client = WebMockClient.new(endpoint, **options)
46
46
  @webmock_client = WebMockClient.new(webmock_endpoint, **options)
47
47
 
48
+ @endpoint = endpoint
48
49
  @scheme = scheme
49
50
  @authority = authority
50
51
  end
@@ -210,7 +211,7 @@ if defined?(Async::HTTP)
210
211
  def build_response(webmock_response)
211
212
  headers = (webmock_response.headers || {}).each_with_object([]) do |(k, value), o|
212
213
  Array(value).each do |v|
213
- o.push [k, v]
214
+ o.push [k, v] unless k.downcase == 'content-length' # async-http appends the exact content-length automatically
214
215
  end
215
216
  end
216
217
 
@@ -7,7 +7,7 @@ rescue LoadError
7
7
  end
8
8
 
9
9
  if defined?(Curl)
10
- WebMock::VersionChecker.new('Curb', Curl::CURB_VERSION, '0.7.16', '1.0.1', ['0.8.7']).check_version!
10
+ WebMock::VersionChecker.new('Curb', Curl::CURB_VERSION, '0.7.16', '1.2.2', ['0.8.7']).check_version!
11
11
 
12
12
  module WebMock
13
13
  module HttpLibAdapters
@@ -32,8 +32,8 @@ if defined?(Curl)
32
32
  status, headers = nil, {}
33
33
 
34
34
  header_string.split(/\r\n/).each do |header|
35
- if header =~ %r|^HTTP/1.[01] \d\d\d (.*)|
36
- status = $1
35
+ if header =~ %r{\AHTTP/(1\.[01]|2) (\d{3})\s*(.*)}
36
+ status = $3
37
37
  else
38
38
  parts = header.split(':', 2)
39
39
  unless parts.empty?
@@ -313,6 +313,7 @@ if defined?(Curl)
313
313
  def response_code
314
314
  @response_code ||= super
315
315
  end
316
+ alias code response_code
316
317
 
317
318
  def header_str
318
319
  @header_str ||= super
@@ -28,9 +28,6 @@ module HTTP
28
28
  headers = webmock_response.headers || {}
29
29
  uri = normalize_uri(request_signature && request_signature.uri)
30
30
 
31
- # HTTP.rb 3.0+ uses a keyword argument to pass the encoding, but 1.x
32
- # and 2.x use a positional argument, and 0.x don't support supplying
33
- # the encoding.
34
31
  body = build_http_rb_response_body_from_webmock_response(webmock_response)
35
32
 
36
33
  return new(status, "1.1", headers, body, uri) if HTTP::VERSION < "1.0.0"
@@ -46,6 +43,17 @@ module HTTP
46
43
  })
47
44
  end
48
45
 
46
+ # 6.0.0 changed Response.new from a positional hash to keyword arguments.
47
+ if HTTP::VERSION >= '6.0.0'
48
+ return new(
49
+ status: status,
50
+ version: "1.1",
51
+ headers: headers,
52
+ body: body,
53
+ request: request,
54
+ )
55
+ end
56
+
49
57
  new({
50
58
  status: status,
51
59
  version: "1.1",
@@ -10,21 +10,32 @@ module HTTP
10
10
 
11
11
  def readpartial(size = nil, outbuf = nil)
12
12
  unless size
13
- if defined?(HTTP::Client::BUFFER_SIZE)
14
- size = HTTP::Client::BUFFER_SIZE
15
- elsif defined?(HTTP::Connection::BUFFER_SIZE)
13
+ if defined?(HTTP::Connection::BUFFER_SIZE)
16
14
  size = HTTP::Connection::BUFFER_SIZE
15
+ elsif defined?(HTTP::Client::BUFFER_SIZE)
16
+ size = HTTP::Client::BUFFER_SIZE
17
17
  end
18
18
  end
19
19
 
20
- chunk = @io.read size, outbuf
21
- chunk.force_encoding(@encoding) if chunk
20
+ chunk = @io.read(size, outbuf)
21
+
22
+ # HTTP.rb 6.0+ expects EOFError at end-of-stream instead of nil
23
+ if chunk.nil?
24
+ raise EOFError if HTTP::VERSION >= "6.0.0"
25
+ return nil
26
+ end
27
+
28
+ chunk.force_encoding(@encoding)
22
29
  end
23
30
 
24
31
  def close
25
32
  @io.close
26
33
  end
27
34
 
35
+ def finished_request?
36
+ @io.eof?
37
+ end
38
+
28
39
  def sequence_id
29
40
  -1
30
41
  end
@@ -43,7 +43,10 @@ module HTTP
43
43
  invoke_callbacks(webmock_response, real_request: false)
44
44
  response = ::HTTP::Response.from_webmock @request, webmock_response, request_signature
45
45
 
46
- @options.features.each { |_name, feature| response = feature.wrap_response(response) }
46
+ # HTTP.rb 6.0+ wraps responses in reverse feature order
47
+ features = @options.features.values
48
+ features = features.reverse if HTTP::VERSION >= "6.0.0"
49
+ features.each { |feature| response = feature.wrap_response(response) }
47
50
  response
48
51
  end
49
52
 
@@ -12,19 +12,25 @@ module WebMock
12
12
  adapter_for :net_http
13
13
 
14
14
  OriginalNetHTTP = Net::HTTP unless const_defined?(:OriginalNetHTTP)
15
+ # This will be removed in Ruby 3.5. In Ruby 3.4, const_remove will warn.
16
+ HAS_LEGACY_CONSTANT = Net.const_defined?(:HTTPSession)
15
17
 
16
18
  def self.enable!
17
19
  Net.send(:remove_const, :HTTP)
18
- Net.send(:remove_const, :HTTPSession)
19
20
  Net.send(:const_set, :HTTP, @webMockNetHTTP)
20
- Net.send(:const_set, :HTTPSession, @webMockNetHTTP)
21
+ if HAS_LEGACY_CONSTANT
22
+ remove_silently(Net, :HTTPSession)
23
+ Net.send(:const_set, :HTTPSession, @webMockNetHTTP)
24
+ end
21
25
  end
22
26
 
23
27
  def self.disable!
24
28
  Net.send(:remove_const, :HTTP)
25
- Net.send(:remove_const, :HTTPSession)
26
29
  Net.send(:const_set, :HTTP, OriginalNetHTTP)
27
- Net.send(:const_set, :HTTPSession, OriginalNetHTTP)
30
+ if HAS_LEGACY_CONSTANT
31
+ remove_silently(Net, :HTTPSession)
32
+ Net.send(:const_set, :HTTPSession, OriginalNetHTTP)
33
+ end
28
34
 
29
35
  #copy all constants from @webMockNetHTTP to original Net::HTTP
30
36
  #in case any constants were added to @webMockNetHTTP instead of Net::HTTP
@@ -37,6 +43,14 @@ module WebMock
37
43
  end
38
44
  end
39
45
 
46
+ def self.remove_silently(mod, const) #:nodoc:
47
+ # Don't warn on removing the deprecated constant
48
+ verbose, $VERBOSE = $VERBOSE, nil
49
+ mod.send(:remove_const, const)
50
+ ensure
51
+ $VERBOSE = verbose
52
+ end
53
+
40
54
  @webMockNetHTTP = Class.new(Net::HTTP) do
41
55
  class << self
42
56
  def socket_type
@@ -186,9 +200,9 @@ module WebMock
186
200
 
187
201
 
188
202
  def check_right_http_connection
189
- unless @@alredy_checked_for_right_http_connection ||= false
203
+ unless @@already_checked_for_right_http_connection ||= false
190
204
  WebMock::NetHTTPUtility.puts_warning_for_right_http_if_needed
191
- @@alredy_checked_for_right_http_connection = true
205
+ @@already_checked_for_right_http_connection = true
192
206
  end
193
207
  end
194
208
  end
@@ -6,7 +6,7 @@ rescue LoadError
6
6
  # patron not found
7
7
  end
8
8
 
9
- if defined?(::Patron)
9
+ if defined?(::Patron::Session)
10
10
  module WebMock
11
11
  module HttpLibAdapters
12
12
  class PatronAdapter < ::WebMock::HttpLibAdapter
@@ -172,7 +172,7 @@ if defined?(Typhoeus)
172
172
  request.execute_headers_callbacks(response)
173
173
  end
174
174
  if request.respond_to?(:streaming?) && request.streaming?
175
- response.options[:response_body] = ""
175
+ response.options[:response_body] = "".dup
176
176
  request.on_body.each { |callback| callback.call(webmock_response.body, response) }
177
177
  end
178
178
  request.finish(response)
@@ -84,11 +84,14 @@ module WebMock
84
84
  URIAddressablePattern.new(uri)
85
85
  elsif uri.respond_to?(:call)
86
86
  URICallablePattern.new(uri)
87
+ elsif uri.is_a?(::URI::Generic)
88
+ URIStringPattern.new(uri.to_s)
89
+ elsif uri.respond_to?(:to_str)
90
+ URIStringPattern.new(uri.to_str)
87
91
  else
88
- URIStringPattern.new(uri)
92
+ raise ArgumentError.new("URI should be a String, Regexp, Addressable::Template, a callable object, or respond to #to_str. Got: #{uri.class}")
89
93
  end
90
94
  end
91
-
92
95
  end
93
96
 
94
97
 
@@ -303,12 +306,14 @@ module WebMock
303
306
  def body_as_hash(body, content_type)
304
307
  case body_format(content_type)
305
308
  when :json then
306
- WebMock::Util::JSON.parse(body)
309
+ WebMock::Util::Parsers::JSON.parse(body)
307
310
  when :xml then
308
- Crack::XML.parse(body)
311
+ WebMock::Util::Parsers::XML.parse(body)
309
312
  else
310
313
  WebMock::Util::QueryMapper.query_to_values(body, notation: Config.instance.query_values_notation)
311
314
  end
315
+ rescue WebMock::Util::Parsers::ParseError
316
+ nil
312
317
  end
313
318
 
314
319
  def body_format(content_type)
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This is a copy of https://github.com/jnunemaker/crack/blob/master/lib/crack/json.rb
4
+ # with date parsing removed
5
+ # Copyright (c) 2004-2008 David Heinemeier Hansson
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
7
+ # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9
+
10
+ require_relative "parse_error"
11
+
12
+ module WebMock
13
+ module Util
14
+ module Parsers
15
+ class JSON
16
+ def self.parse(json)
17
+ yaml = unescape(convert_json_to_yaml(json))
18
+ YAML.load(yaml)
19
+ rescue ArgumentError, Psych::SyntaxError => e
20
+ raise ParseError, "Invalid JSON string: #{yaml}, Error: #{e.inspect}"
21
+ end
22
+
23
+ protected
24
+
25
+ def self.unescape(str)
26
+ str.gsub(/\\u([0-9a-f]{4})/) { [$1.hex].pack("U") }
27
+ end
28
+
29
+ # Ensure that ":" and "," are always followed by a space
30
+ def self.convert_json_to_yaml(json) #:nodoc:
31
+ scanner, quoting, marks, times = StringScanner.new(json), false, [], []
32
+ while scanner.scan_until(/(\\['"]|['":,\\]|\\.)/)
33
+ case char = scanner[1]
34
+ when '"', "'"
35
+ if !quoting
36
+ quoting = char
37
+ elsif quoting == char
38
+ quoting = false
39
+ end
40
+ when ":",","
41
+ marks << scanner.pos - 1 unless quoting
42
+ when "\\"
43
+ scanner.skip(/\\/)
44
+ end
45
+ end
46
+
47
+ if marks.empty?
48
+ json.gsub(/\\\//, '/')
49
+ else
50
+ left_pos = [-1].push(*marks)
51
+ right_pos = marks << json.bytesize
52
+ output = []
53
+
54
+ left_pos.each_with_index do |left, i|
55
+ if json.respond_to?(:byteslice)
56
+ output << json.byteslice(left.succ..right_pos[i])
57
+ else
58
+ output << json[left.succ..right_pos[i]]
59
+ end
60
+ end
61
+
62
+ output = output * " "
63
+
64
+ times.each { |i| output[i-1] = ' ' }
65
+ output.gsub!(/\\\//, '/')
66
+ output
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,7 @@
1
+ module WebMock
2
+ module Util
3
+ module Parsers
4
+ class ParseError < StandardError; end
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,16 @@
1
+ require_relative "parse_error"
2
+ require "crack/xml"
3
+
4
+ module WebMock
5
+ module Util
6
+ module Parsers
7
+ class XML
8
+ def self.parse(xml)
9
+ ::Crack::XML.parse(xml)
10
+ rescue ::REXML::ParseException => e
11
+ raise ParseError, "Invalid XML string: #{xml}, Error: #{e.inspect}"
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module WebMock
4
- VERSION = '3.23.1' unless defined?(::WebMock::VERSION)
4
+ VERSION = '3.26.2' unless defined?(::WebMock::VERSION)
5
5
  end
data/lib/webmock.rb CHANGED
@@ -4,7 +4,6 @@ require 'singleton'
4
4
 
5
5
  require 'addressable/uri'
6
6
  require 'addressable/template'
7
- require 'crack/xml'
8
7
 
9
8
  require_relative 'webmock/deprecation'
10
9
  require_relative 'webmock/version'
@@ -17,7 +16,8 @@ require_relative 'webmock/util/headers'
17
16
  require_relative 'webmock/util/hash_counter'
18
17
  require_relative 'webmock/util/hash_keys_stringifier'
19
18
  require_relative 'webmock/util/values_stringifier'
20
- require_relative 'webmock/util/json'
19
+ require_relative 'webmock/util/parsers/json'
20
+ require_relative 'webmock/util/parsers/xml'
21
21
  require_relative 'webmock/util/version_checker'
22
22
  require_relative 'webmock/util/hash_validator'
23
23
 
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webmock
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.23.1
4
+ version: 3.26.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bartosz Blimke
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-05-24 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: addressable
@@ -198,20 +197,6 @@ dependencies:
198
197
  - - ">="
199
198
  - !ruby/object:Gem::Version
200
199
  version: 2.2.4
201
- - !ruby/object:Gem::Dependency
202
- name: mutex_m
203
- requirement: !ruby/object:Gem::Requirement
204
- requirements:
205
- - - ">="
206
- - !ruby/object:Gem::Version
207
- version: '0'
208
- type: :development
209
- prerelease: false
210
- version_requirements: !ruby/object:Gem::Requirement
211
- requirements:
212
- - - ">="
213
- - !ruby/object:Gem::Version
214
- version: '0'
215
200
  - !ruby/object:Gem::Dependency
216
201
  name: excon
217
202
  requirement: !ruby/object:Gem::Requirement
@@ -359,7 +344,9 @@ files:
359
344
  - lib/webmock/util/hash_keys_stringifier.rb
360
345
  - lib/webmock/util/hash_validator.rb
361
346
  - lib/webmock/util/headers.rb
362
- - lib/webmock/util/json.rb
347
+ - lib/webmock/util/parsers/json.rb
348
+ - lib/webmock/util/parsers/parse_error.rb
349
+ - lib/webmock/util/parsers/xml.rb
363
350
  - lib/webmock/util/query_mapper.rb
364
351
  - lib/webmock/util/uri.rb
365
352
  - lib/webmock/util/values_stringifier.rb
@@ -371,11 +358,10 @@ licenses:
371
358
  - MIT
372
359
  metadata:
373
360
  bug_tracker_uri: https://github.com/bblimke/webmock/issues
374
- changelog_uri: https://github.com/bblimke/webmock/blob/v3.23.1/CHANGELOG.md
375
- documentation_uri: https://www.rubydoc.info/gems/webmock/3.23.1
376
- source_code_uri: https://github.com/bblimke/webmock/tree/v3.23.1
361
+ changelog_uri: https://github.com/bblimke/webmock/blob/v3.26.2/CHANGELOG.md
362
+ documentation_uri: https://www.rubydoc.info/gems/webmock/3.26.2
363
+ source_code_uri: https://github.com/bblimke/webmock/tree/v3.26.2
377
364
  wiki_uri: https://github.com/bblimke/webmock/wiki
378
- post_install_message:
379
365
  rdoc_options: []
380
366
  require_paths:
381
367
  - lib
@@ -383,15 +369,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
383
369
  requirements:
384
370
  - - ">="
385
371
  - !ruby/object:Gem::Version
386
- version: '2.5'
372
+ version: '2.6'
387
373
  required_rubygems_version: !ruby/object:Gem::Requirement
388
374
  requirements:
389
375
  - - ">="
390
376
  - !ruby/object:Gem::Version
391
377
  version: '0'
392
378
  requirements: []
393
- rubygems_version: 3.5.7
394
- signing_key:
379
+ rubygems_version: 4.1.0.dev
395
380
  specification_version: 4
396
381
  summary: Library for stubbing HTTP requests in Ruby.
397
382
  test_files: []
@@ -1,69 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # This is a copy of https://github.com/jnunemaker/crack/blob/master/lib/crack/json.rb
4
- # with date parsing removed
5
- # Copyright (c) 2004-2008 David Heinemeier Hansson
6
- # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
7
- # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9
-
10
- module WebMock
11
- module Util
12
- class JSON
13
- class ParseError < StandardError; end
14
-
15
- def self.parse(json)
16
- yaml = unescape(convert_json_to_yaml(json))
17
- YAML.load(yaml)
18
- rescue ArgumentError => e
19
- raise ParseError, "Invalid JSON string: #{yaml}, Error: #{e.inspect}"
20
- end
21
-
22
- protected
23
- def self.unescape(str)
24
- str.gsub(/\\u([0-9a-f]{4})/) { [$1.hex].pack("U") }
25
- end
26
-
27
- # Ensure that ":" and "," are always followed by a space
28
- def self.convert_json_to_yaml(json) #:nodoc:
29
- scanner, quoting, marks, times = StringScanner.new(json), false, [], []
30
- while scanner.scan_until(/(\\['"]|['":,\\]|\\.)/)
31
- case char = scanner[1]
32
- when '"', "'"
33
- if !quoting
34
- quoting = char
35
- elsif quoting == char
36
- quoting = false
37
- end
38
- when ":",","
39
- marks << scanner.pos - 1 unless quoting
40
- when "\\"
41
- scanner.skip(/\\/)
42
- end
43
- end
44
-
45
- if marks.empty?
46
- json.gsub(/\\\//, '/')
47
- else
48
- left_pos = [-1].push(*marks)
49
- right_pos = marks << json.bytesize
50
- output = []
51
-
52
- left_pos.each_with_index do |left, i|
53
- if json.respond_to?(:byteslice)
54
- output << json.byteslice(left.succ..right_pos[i])
55
- else
56
- output << json[left.succ..right_pos[i]]
57
- end
58
- end
59
-
60
- output = output * " "
61
-
62
- times.each { |i| output[i-1] = ' ' }
63
- output.gsub!(/\\\//, '/')
64
- output
65
- end
66
- end
67
- end
68
- end
69
- end