bson 4.11.1 → 4.14.0
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 +4 -4
 - checksums.yaml.gz.sig +0 -0
 - data/README.md +4 -7
 - data/ext/bson/bson-native.h +2 -0
 - data/ext/bson/init.c +9 -0
 - data/ext/bson/read.c +29 -0
 - data/lib/bson/active_support.rb +1 -0
 - data/lib/bson/array.rb +2 -1
 - data/lib/bson/big_decimal.rb +67 -0
 - data/lib/bson/binary.rb +8 -5
 - data/lib/bson/boolean.rb +2 -1
 - data/lib/bson/code.rb +2 -1
 - data/lib/bson/code_with_scope.rb +2 -1
 - data/lib/bson/config.rb +1 -0
 - data/lib/bson/date.rb +1 -0
 - data/lib/bson/date_time.rb +1 -0
 - data/lib/bson/db_pointer.rb +2 -1
 - data/lib/bson/dbref.rb +125 -0
 - data/lib/bson/decimal128/builder.rb +27 -20
 - data/lib/bson/decimal128.rb +27 -12
 - data/lib/bson/document.rb +61 -18
 - data/lib/bson/environment.rb +1 -0
 - data/lib/bson/error.rb +7 -0
 - data/lib/bson/ext_json.rb +24 -11
 - data/lib/bson/false_class.rb +2 -1
 - data/lib/bson/float.rb +21 -32
 - data/lib/bson/hash.rb +15 -6
 - data/lib/bson/int32.rb +3 -2
 - data/lib/bson/int64.rb +3 -2
 - data/lib/bson/integer.rb +3 -2
 - data/lib/bson/json.rb +1 -0
 - data/lib/bson/max_key.rb +3 -2
 - data/lib/bson/min_key.rb +3 -2
 - data/lib/bson/nil_class.rb +2 -1
 - data/lib/bson/object.rb +1 -0
 - data/lib/bson/object_id.rb +4 -3
 - data/lib/bson/open_struct.rb +1 -0
 - data/lib/bson/regexp.rb +17 -6
 - data/lib/bson/registry.rb +1 -0
 - data/lib/bson/specialized.rb +1 -0
 - data/lib/bson/string.rb +3 -2
 - data/lib/bson/symbol.rb +2 -1
 - data/lib/bson/time.rb +4 -3
 - data/lib/bson/time_with_zone.rb +1 -0
 - data/lib/bson/timestamp.rb +3 -2
 - data/lib/bson/true_class.rb +2 -1
 - data/lib/bson/undefined.rb +2 -1
 - data/lib/bson/version.rb +2 -1
 - data/lib/bson.rb +8 -5
 - data/lib/bson_native.bundle +0 -0
 - data/spec/README.md +14 -0
 - data/spec/bson/big_decimal_spec.rb +316 -0
 - data/spec/bson/binary_spec.rb +1 -1
 - data/spec/bson/binary_uuid_spec.rb +12 -0
 - data/spec/bson/dbref_spec.rb +461 -0
 - data/spec/bson/decimal128_spec.rb +16 -0
 - data/spec/bson/document_as_spec.rb +46 -0
 - data/spec/bson/document_spec.rb +43 -1
 - data/spec/bson/ext_json_parse_spec.rb +37 -0
 - data/spec/bson/hash_as_spec.rb +57 -0
 - data/spec/bson/hash_spec.rb +32 -0
 - data/spec/bson/int64_spec.rb +4 -24
 - data/spec/bson/raw_spec.rb +7 -1
 - data/spec/bson/regexp_spec.rb +52 -0
 - data/spec/runners/common_driver.rb +1 -1
 - data/spec/shared/LICENSE +20 -0
 - data/spec/shared/bin/get-mongodb-download-url +17 -0
 - data/spec/shared/bin/s3-copy +45 -0
 - data/spec/shared/bin/s3-upload +69 -0
 - data/spec/shared/lib/mrss/child_process_helper.rb +80 -0
 - data/spec/shared/lib/mrss/cluster_config.rb +231 -0
 - data/spec/shared/lib/mrss/constraints.rb +386 -0
 - data/spec/shared/lib/mrss/docker_runner.rb +271 -0
 - data/spec/shared/lib/mrss/event_subscriber.rb +200 -0
 - data/spec/shared/lib/mrss/lite_constraints.rb +191 -0
 - data/spec/shared/lib/mrss/server_version_registry.rb +120 -0
 - data/spec/shared/lib/mrss/spec_organizer.rb +179 -0
 - data/spec/shared/lib/mrss/utils.rb +15 -0
 - data/spec/shared/share/Dockerfile.erb +338 -0
 - data/spec/shared/share/haproxy-1.conf +16 -0
 - data/spec/shared/share/haproxy-2.conf +17 -0
 - data/spec/shared/shlib/distro.sh +74 -0
 - data/spec/shared/shlib/server.sh +367 -0
 - data/spec/shared/shlib/set_env.sh +131 -0
 - data/spec/spec_helper.rb +20 -0
 - data/spec/spec_tests/common_driver_spec.rb +2 -1
 - data/spec/spec_tests/data/corpus/binary.json +33 -0
 - data/spec/spec_tests/data/corpus/dbref.json +21 -1
 - data/spec/spec_tests/data/corpus/document.json +4 -0
 - data/spec/spec_tests/data/corpus/regex.json +2 -2
 - data/spec/spec_tests/data/corpus/top.json +20 -9
 - data/spec/support/spec_config.rb +2 -1
 - data.tar.gz.sig +0 -0
 - metadata +157 -106
 - metadata.gz.sig +0 -0
 
    
        data/lib/bson/decimal128.rb
    CHANGED
    
    | 
         @@ -1,3 +1,4 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
       1 
2 
     | 
    
         
             
            # Copyright (C) 2016-2020 MongoDB Inc.
         
     | 
| 
       2 
3 
     | 
    
         
             
            #
         
     | 
| 
       3 
4 
     | 
    
         
             
            # Licensed under the Apache License, Version 2.0 (the "License");
         
     | 
| 
         @@ -23,32 +24,32 @@ module BSON 
     | 
|
| 
       23 
24 
     | 
    
         
             
                # A Decimal128 is type 0x13 in the BSON spec.
         
     | 
| 
       24 
25 
     | 
    
         
             
                #
         
     | 
| 
       25 
26 
     | 
    
         
             
                # @since 4.2.0
         
     | 
| 
       26 
     | 
    
         
            -
                BSON_TYPE = 19.chr 
     | 
| 
      
 27 
     | 
    
         
            +
                BSON_TYPE = ::String.new(19.chr, encoding: BINARY).freeze
         
     | 
| 
       27 
28 
     | 
    
         | 
| 
       28 
29 
     | 
    
         
             
                # Exponent offset.
         
     | 
| 
       29 
30 
     | 
    
         
             
                #
         
     | 
| 
       30 
31 
     | 
    
         
             
                # @since 4.2.0
         
     | 
| 
       31 
     | 
    
         
            -
                EXPONENT_OFFSET = 6176 
     | 
| 
      
 32 
     | 
    
         
            +
                EXPONENT_OFFSET = 6176
         
     | 
| 
       32 
33 
     | 
    
         | 
| 
       33 
34 
     | 
    
         
             
                # Minimum exponent.
         
     | 
| 
       34 
35 
     | 
    
         
             
                #
         
     | 
| 
       35 
36 
     | 
    
         
             
                # @since 4.2.0
         
     | 
| 
       36 
     | 
    
         
            -
                MIN_EXPONENT = -6176 
     | 
| 
      
 37 
     | 
    
         
            +
                MIN_EXPONENT = -6176
         
     | 
| 
       37 
38 
     | 
    
         | 
| 
       38 
39 
     | 
    
         
             
                # Maximum exponent.
         
     | 
| 
       39 
40 
     | 
    
         
             
                #
         
     | 
| 
       40 
41 
     | 
    
         
             
                # @since 4.2.0
         
     | 
| 
       41 
     | 
    
         
            -
                MAX_EXPONENT = 6111 
     | 
| 
      
 42 
     | 
    
         
            +
                MAX_EXPONENT = 6111
         
     | 
| 
       42 
43 
     | 
    
         | 
| 
       43 
44 
     | 
    
         
             
                # Maximum digits of precision.
         
     | 
| 
       44 
45 
     | 
    
         
             
                #
         
     | 
| 
       45 
46 
     | 
    
         
             
                # @since 4.2.0
         
     | 
| 
       46 
     | 
    
         
            -
                MAX_DIGITS_OF_PRECISION = 34 
     | 
| 
      
 47 
     | 
    
         
            +
                MAX_DIGITS_OF_PRECISION = 34
         
     | 
| 
       47 
48 
     | 
    
         | 
| 
       48 
49 
     | 
    
         
             
                # Key for this type when converted to extended json.
         
     | 
| 
       49 
50 
     | 
    
         
             
                #
         
     | 
| 
       50 
51 
     | 
    
         
             
                # @since 4.2.0
         
     | 
| 
       51 
     | 
    
         
            -
                EXTENDED_JSON_KEY = "$numberDecimal" 
     | 
| 
      
 52 
     | 
    
         
            +
                EXTENDED_JSON_KEY = "$numberDecimal"
         
     | 
| 
       52 
53 
     | 
    
         | 
| 
       53 
54 
     | 
    
         
             
                # The native type to which this object can be converted.
         
     | 
| 
       54 
55 
     | 
    
         
             
                #
         
     | 
| 
         @@ -262,7 +263,7 @@ module BSON 
     | 
|
| 
       262 
263 
     | 
    
         
             
                  # The custom error message for this error.
         
     | 
| 
       263 
264 
     | 
    
         
             
                  #
         
     | 
| 
       264 
265 
     | 
    
         
             
                  # @since 4.2.0
         
     | 
| 
       265 
     | 
    
         
            -
                  MESSAGE = 'A Decimal128 can only be created from a String or BigDecimal.' 
     | 
| 
      
 266 
     | 
    
         
            +
                  MESSAGE = 'A Decimal128 can only be created from a String or BigDecimal.'
         
     | 
| 
       266 
267 
     | 
    
         | 
| 
       267 
268 
     | 
    
         
             
                  # Get the custom error message for the exception.
         
     | 
| 
       268 
269 
     | 
    
         
             
                  #
         
     | 
| 
         @@ -288,7 +289,7 @@ module BSON 
     | 
|
| 
       288 
289 
     | 
    
         
             
                  # The custom error message for this error.
         
     | 
| 
       289 
290 
     | 
    
         
             
                  #
         
     | 
| 
       290 
291 
     | 
    
         
             
                  # @since 4.2.0
         
     | 
| 
       291 
     | 
    
         
            -
                  MESSAGE = 'Invalid string format for creating a Decimal128 object.' 
     | 
| 
      
 292 
     | 
    
         
            +
                  MESSAGE = 'Invalid string format for creating a Decimal128 object.'
         
     | 
| 
       292 
293 
     | 
    
         | 
| 
       293 
294 
     | 
    
         
             
                  # Get the custom error message for the exception.
         
     | 
| 
       294 
295 
     | 
    
         
             
                  #
         
     | 
| 
         @@ -303,9 +304,7 @@ module BSON 
     | 
|
| 
       303 
304 
     | 
    
         
             
                  end
         
     | 
| 
       304 
305 
     | 
    
         
             
                end
         
     | 
| 
       305 
306 
     | 
    
         | 
| 
       306 
     | 
    
         
            -
                # Raised when the exponent  
     | 
| 
       307 
     | 
    
         
            -
                #
         
     | 
| 
       308 
     | 
    
         
            -
                # @api private
         
     | 
| 
      
 307 
     | 
    
         
            +
                # Raised when the exponent is outside the valid range.
         
     | 
| 
       309 
308 
     | 
    
         
             
                #
         
     | 
| 
       310 
309 
     | 
    
         
             
                # @since 4.2.0
         
     | 
| 
       311 
310 
     | 
    
         
             
                class InvalidRange < RuntimeError
         
     | 
| 
         @@ -313,7 +312,8 @@ module BSON 
     | 
|
| 
       313 
312 
     | 
    
         
             
                  # The custom error message for this error.
         
     | 
| 
       314 
313 
     | 
    
         
             
                  #
         
     | 
| 
       315 
314 
     | 
    
         
             
                  # @since 4.2.0
         
     | 
| 
       316 
     | 
    
         
            -
                   
     | 
| 
      
 315 
     | 
    
         
            +
                  # @deprecated
         
     | 
| 
      
 316 
     | 
    
         
            +
                  MESSAGE = 'Value out of range for Decimal128 representation.'
         
     | 
| 
       317 
317 
     | 
    
         | 
| 
       318 
318 
     | 
    
         
             
                  # Get the custom error message for the exception.
         
     | 
| 
       319 
319 
     | 
    
         
             
                  #
         
     | 
| 
         @@ -328,6 +328,21 @@ module BSON 
     | 
|
| 
       328 
328 
     | 
    
         
             
                  end
         
     | 
| 
       329 
329 
     | 
    
         
             
                end
         
     | 
| 
       330 
330 
     | 
    
         | 
| 
      
 331 
     | 
    
         
            +
                # Raised when the significand provided is outside the valid range.
         
     | 
| 
      
 332 
     | 
    
         
            +
                #
         
     | 
| 
      
 333 
     | 
    
         
            +
                # @note This class derives from InvalidRange for backwards compatibility,
         
     | 
| 
      
 334 
     | 
    
         
            +
                #   however when RUBY-1806 is implemented it should be changed to derive
         
     | 
| 
      
 335 
     | 
    
         
            +
                #   from the base BSON exception class.
         
     | 
| 
      
 336 
     | 
    
         
            +
                class UnrepresentablePrecision < InvalidRange
         
     | 
| 
      
 337 
     | 
    
         
            +
             
     | 
| 
      
 338 
     | 
    
         
            +
                  # Get the custom error message for the exception.
         
     | 
| 
      
 339 
     | 
    
         
            +
                  #
         
     | 
| 
      
 340 
     | 
    
         
            +
                  # @return [ String ] The error message.
         
     | 
| 
      
 341 
     | 
    
         
            +
                  def message
         
     | 
| 
      
 342 
     | 
    
         
            +
                    'The value contains too much precision for Decimal128 representation'
         
     | 
| 
      
 343 
     | 
    
         
            +
                  end
         
     | 
| 
      
 344 
     | 
    
         
            +
                end
         
     | 
| 
      
 345 
     | 
    
         
            +
             
     | 
| 
       331 
346 
     | 
    
         
             
                Registry.register(BSON_TYPE, self)
         
     | 
| 
       332 
347 
     | 
    
         
             
              end
         
     | 
| 
       333 
348 
     | 
    
         
             
            end
         
     | 
    
        data/lib/bson/document.rb
    CHANGED
    
    | 
         @@ -1,3 +1,4 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
       1 
2 
     | 
    
         
             
            # Copyright (C) 2009-2020 MongoDB Inc.
         
     | 
| 
       2 
3 
     | 
    
         
             
            #
         
     | 
| 
       3 
4 
     | 
    
         
             
            # Licensed under the Apache License, Version 2.0 (the "License");
         
     | 
| 
         @@ -269,27 +270,69 @@ module BSON 
     | 
|
| 
       269 
270 
     | 
    
         
             
                  end
         
     | 
| 
       270 
271 
     | 
    
         
             
                end
         
     | 
| 
       271 
272 
     | 
    
         | 
| 
       272 
     | 
    
         
            -
                 
     | 
| 
       273 
     | 
    
         
            -
             
     | 
| 
       274 
     | 
    
         
            -
             
     | 
| 
       275 
     | 
    
         
            -
             
     | 
| 
       276 
     | 
    
         
            -
             
     | 
| 
       277 
     | 
    
         
            -
             
     | 
| 
       278 
     | 
    
         
            -
             
     | 
| 
       279 
     | 
    
         
            -
             
     | 
| 
       280 
     | 
    
         
            -
             
     | 
| 
       281 
     | 
    
         
            -
             
     | 
| 
       282 
     | 
    
         
            -
             
     | 
| 
       283 
     | 
    
         
            -
             
     | 
| 
       284 
     | 
    
         
            -
             
     | 
| 
       285 
     | 
    
         
            -
             
     | 
| 
       286 
     | 
    
         
            -
             
     | 
| 
       287 
     | 
    
         
            -
             
     | 
| 
       288 
     | 
    
         
            -
                   
     | 
| 
       289 
     | 
    
         
            -
                     
     | 
| 
      
 273 
     | 
    
         
            +
                # Slices a document to include only the given keys.
         
     | 
| 
      
 274 
     | 
    
         
            +
                # Will normalize symbol keys into strings.
         
     | 
| 
      
 275 
     | 
    
         
            +
                # (this method is backported from ActiveSupport::Hash)
         
     | 
| 
      
 276 
     | 
    
         
            +
                #
         
     | 
| 
      
 277 
     | 
    
         
            +
                # @example Get a document/hash with only the `name` and `age` fields present
         
     | 
| 
      
 278 
     | 
    
         
            +
                #   document # => { _id: <ObjectId>, :name => "John", :age => 30, :location => "Earth" }
         
     | 
| 
      
 279 
     | 
    
         
            +
                #   document.slice(:name, 'age') # => { "name": "John", "age" => 30 }
         
     | 
| 
      
 280 
     | 
    
         
            +
                #   document.slice('name') # => { "name" => "John" }
         
     | 
| 
      
 281 
     | 
    
         
            +
                #   document.slice(:foo) # => {}
         
     | 
| 
      
 282 
     | 
    
         
            +
                #
         
     | 
| 
      
 283 
     | 
    
         
            +
                # @param [ Array<String, Symbol> ] *keys Keys, that will be kept in the resulting document
         
     | 
| 
      
 284 
     | 
    
         
            +
                #
         
     | 
| 
      
 285 
     | 
    
         
            +
                # @return [ BSON::Document ] The document with only the selected keys
         
     | 
| 
      
 286 
     | 
    
         
            +
                #
         
     | 
| 
      
 287 
     | 
    
         
            +
                # @since 4.3.1
         
     | 
| 
      
 288 
     | 
    
         
            +
                def slice(*keys)
         
     | 
| 
      
 289 
     | 
    
         
            +
                  keys.each_with_object(self.class.new) do |key, hash|
         
     | 
| 
      
 290 
     | 
    
         
            +
                    if key?(key)
         
     | 
| 
      
 291 
     | 
    
         
            +
                      hash[key] = self[key]
         
     | 
| 
      
 292 
     | 
    
         
            +
                    end
         
     | 
| 
       290 
293 
     | 
    
         
             
                  end
         
     | 
| 
       291 
294 
     | 
    
         
             
                end
         
     | 
| 
       292 
295 
     | 
    
         | 
| 
      
 296 
     | 
    
         
            +
                # Returns a new document consisting of the current document minus the
         
     | 
| 
      
 297 
     | 
    
         
            +
                # specified keys.
         
     | 
| 
      
 298 
     | 
    
         
            +
                #
         
     | 
| 
      
 299 
     | 
    
         
            +
                # The keys to be removed can be specified as either strings or symbols.
         
     | 
| 
      
 300 
     | 
    
         
            +
                #
         
     | 
| 
      
 301 
     | 
    
         
            +
                # @example Get a document/hash with only the `name` and `age` fields removed
         
     | 
| 
      
 302 
     | 
    
         
            +
                #   document # => { _id: <ObjectId>, :name => 'John', :age => 30, :location => 'Earth' }
         
     | 
| 
      
 303 
     | 
    
         
            +
                #   document.except(:name, 'age') # => { _id: <ObjectId>, location: 'Earth' }
         
     | 
| 
      
 304 
     | 
    
         
            +
                #
         
     | 
| 
      
 305 
     | 
    
         
            +
                # @param [ Array<String, Symbol> ] *keys Keys, that will be removed in the resulting document
         
     | 
| 
      
 306 
     | 
    
         
            +
                #
         
     | 
| 
      
 307 
     | 
    
         
            +
                # @return [ BSON::Document ] The document with the specified keys removed.
         
     | 
| 
      
 308 
     | 
    
         
            +
                #
         
     | 
| 
      
 309 
     | 
    
         
            +
                # @note This method is always defined, even if Hash already contains a
         
     | 
| 
      
 310 
     | 
    
         
            +
                #   definition of #except, because ActiveSupport unconditionally defines
         
     | 
| 
      
 311 
     | 
    
         
            +
                #   its version of #except which doesn't work for BSON::Document which
         
     | 
| 
      
 312 
     | 
    
         
            +
                #   causes problems if ActiveSupport is loaded after bson-ruby is.
         
     | 
| 
      
 313 
     | 
    
         
            +
                def except(*keys)
         
     | 
| 
      
 314 
     | 
    
         
            +
                  copy = dup
         
     | 
| 
      
 315 
     | 
    
         
            +
                  keys.each {|key| copy.delete(key)}
         
     | 
| 
      
 316 
     | 
    
         
            +
                  copy
         
     | 
| 
      
 317 
     | 
    
         
            +
                end
         
     | 
| 
      
 318 
     | 
    
         
            +
             
     | 
| 
      
 319 
     | 
    
         
            +
                def symbolize_keys!
         
     | 
| 
      
 320 
     | 
    
         
            +
                  raise ArgumentError, 'symbolize_keys! is not supported on BSON::Document instances. Please convert the document to hash first (using #to_h), then call #symbolize_keys! on the Hash instance'
         
     | 
| 
      
 321 
     | 
    
         
            +
                end
         
     | 
| 
      
 322 
     | 
    
         
            +
             
     | 
| 
      
 323 
     | 
    
         
            +
                # Override the Hash implementation of to_bson_normalized_value.
         
     | 
| 
      
 324 
     | 
    
         
            +
                #
         
     | 
| 
      
 325 
     | 
    
         
            +
                # BSON::Document is already of the correct type and already provides
         
     | 
| 
      
 326 
     | 
    
         
            +
                # indifferent access to keys, hence no further conversions are necessary.
         
     | 
| 
      
 327 
     | 
    
         
            +
                #
         
     | 
| 
      
 328 
     | 
    
         
            +
                # Attempting to perform Hash's conversion on Document instances converts
         
     | 
| 
      
 329 
     | 
    
         
            +
                # DBRefs to Documents which is wrong.
         
     | 
| 
      
 330 
     | 
    
         
            +
                #
         
     | 
| 
      
 331 
     | 
    
         
            +
                # @return [ BSON::Document ] The normalized hash.
         
     | 
| 
      
 332 
     | 
    
         
            +
                def to_bson_normalized_value
         
     | 
| 
      
 333 
     | 
    
         
            +
                  self
         
     | 
| 
      
 334 
     | 
    
         
            +
                end
         
     | 
| 
      
 335 
     | 
    
         
            +
             
     | 
| 
       293 
336 
     | 
    
         
             
                private
         
     | 
| 
       294 
337 
     | 
    
         | 
| 
       295 
338 
     | 
    
         
             
                def convert_key(key)
         
     | 
    
        data/lib/bson/environment.rb
    CHANGED
    
    
    
        data/lib/bson/error.rb
    CHANGED
    
    | 
         @@ -1,3 +1,4 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
       1 
2 
     | 
    
         
             
            module BSON
         
     | 
| 
       2 
3 
     | 
    
         
             
              # Base exception class for all BSON-related errors.
         
     | 
| 
       3 
4 
     | 
    
         
             
              #
         
     | 
| 
         @@ -23,5 +24,11 @@ module BSON 
     | 
|
| 
       23 
24 
     | 
    
         
             
                # itself to BSON.
         
     | 
| 
       24 
25 
     | 
    
         
             
                class UnserializableClass < Error
         
     | 
| 
       25 
26 
     | 
    
         
             
                end
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
                # Exception raised when there is an invalid argument passed into the
         
     | 
| 
      
 29 
     | 
    
         
            +
                # constructor of regexp object. This includes when the argument contains
         
     | 
| 
      
 30 
     | 
    
         
            +
                # a null byte.
         
     | 
| 
      
 31 
     | 
    
         
            +
                class InvalidRegexpPattern < Error
         
     | 
| 
      
 32 
     | 
    
         
            +
                end
         
     | 
| 
       26 
33 
     | 
    
         
             
              end
         
     | 
| 
       27 
34 
     | 
    
         
             
            end
         
     | 
    
        data/lib/bson/ext_json.rb
    CHANGED
    
    | 
         @@ -1,3 +1,4 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
       1 
2 
     | 
    
         
             
            # Copyright (C) 2019-2020 MongoDB Inc.
         
     | 
| 
       2 
3 
     | 
    
         
             
            #
         
     | 
| 
       3 
4 
     | 
    
         
             
            # Licensed under the Apache License, Version 2.0 (the "License");
         
     | 
| 
         @@ -138,7 +139,7 @@ module BSON 
     | 
|
| 
       138 
139 
     | 
    
         
             
                    return {}
         
     | 
| 
       139 
140 
     | 
    
         
             
                  end
         
     | 
| 
       140 
141 
     | 
    
         | 
| 
       141 
     | 
    
         
            -
                  if  
     | 
| 
      
 142 
     | 
    
         
            +
                  if dbref?(hash)
         
     | 
| 
       142 
143 
     | 
    
         
             
                    # Legacy dbref handling.
         
     | 
| 
       143 
144 
     | 
    
         
             
                    # Note that according to extended json spec, only hash values (but
         
     | 
| 
       144 
145 
     | 
    
         
             
                    # not the top-level BSON document itself) may be of type "dbref".
         
     | 
| 
         @@ -147,10 +148,6 @@ module BSON 
     | 
|
| 
       147 
148 
     | 
    
         
             
                    # logic to top level hashes doesn't cause harm.
         
     | 
| 
       148 
149 
     | 
    
         
             
                    hash = hash.dup
         
     | 
| 
       149 
150 
     | 
    
         
             
                    ref = hash.delete('$ref')
         
     | 
| 
       150 
     | 
    
         
            -
                    # $ref can be a string value or an ObjectId
         
     | 
| 
       151 
     | 
    
         
            -
                    unless ref.is_a?(String)
         
     | 
| 
       152 
     | 
    
         
            -
                      raise Error::ExtJSONParseError, "Invalid $ref value: #{ref}"
         
     | 
| 
       153 
     | 
    
         
            -
                    end
         
     | 
| 
       154 
151 
     | 
    
         
             
                    # $id, if present, can be anything
         
     | 
| 
       155 
152 
     | 
    
         
             
                    id = hash.delete('$id')
         
     | 
| 
       156 
153 
     | 
    
         
             
                    if id.is_a?(Hash)
         
     | 
| 
         @@ -163,13 +160,9 @@ module BSON 
     | 
|
| 
       163 
160 
     | 
    
         
             
                    out = {'$ref' => ref, '$id' => id}
         
     | 
| 
       164 
161 
     | 
    
         
             
                    if hash.key?('$db')
         
     | 
| 
       165 
162 
     | 
    
         
             
                      # $db must always be a string, if provided
         
     | 
| 
       166 
     | 
    
         
            -
                      db = hash.delete('$db')
         
     | 
| 
       167 
     | 
    
         
            -
                      unless db.is_a?(String)
         
     | 
| 
       168 
     | 
    
         
            -
                        raise Error::ExtJSONParseError, "Invalid $db value: #{db}"
         
     | 
| 
       169 
     | 
    
         
            -
                      end
         
     | 
| 
       170 
     | 
    
         
            -
                      out['$db'] = db
         
     | 
| 
      
 163 
     | 
    
         
            +
                      out['$db'] = hash.delete('$db')
         
     | 
| 
       171 
164 
     | 
    
         
             
                    end
         
     | 
| 
       172 
     | 
    
         
            -
                    return out.update(hash)
         
     | 
| 
      
 165 
     | 
    
         
            +
                    return out.update(parse_hash(hash))
         
     | 
| 
       173 
166 
     | 
    
         
             
                  end
         
     | 
| 
       174 
167 
     | 
    
         | 
| 
       175 
168 
     | 
    
         
             
                  if hash.length == 1
         
     | 
| 
         @@ -219,6 +212,14 @@ module BSON 
     | 
|
| 
       219 
212 
     | 
    
         
             
                        raise Error::ExtJSONParseError, "Invalid subType value in $binary: #{value}"
         
     | 
| 
       220 
213 
     | 
    
         
             
                      end
         
     | 
| 
       221 
214 
     | 
    
         
             
                      create_binary(encoded_value, subtype)
         
     | 
| 
      
 215 
     | 
    
         
            +
             
     | 
| 
      
 216 
     | 
    
         
            +
                    when '$uuid'
         
     | 
| 
      
 217 
     | 
    
         
            +
                      unless /\A[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}\z/.match(value)
         
     | 
| 
      
 218 
     | 
    
         
            +
                        raise Error::ExtJSONParseError, "Invalid $uuid value: #{value}"
         
     | 
| 
      
 219 
     | 
    
         
            +
                      end
         
     | 
| 
      
 220 
     | 
    
         
            +
             
     | 
| 
      
 221 
     | 
    
         
            +
                      return Binary.from_uuid(value)
         
     | 
| 
      
 222 
     | 
    
         
            +
             
     | 
| 
       222 
223 
     | 
    
         
             
                    when '$code'
         
     | 
| 
       223 
224 
     | 
    
         
             
                      unless value.is_a?(String)
         
     | 
| 
       224 
225 
     | 
    
         
             
                        raise Error::ExtJSONParseError, "Invalid $code value: #{value}"
         
     | 
| 
         @@ -354,6 +355,9 @@ module BSON 
     | 
|
| 
       354 
355 
     | 
    
         | 
| 
       355 
356 
     | 
    
         
             
                module_function def map_hash(hash, **options)
         
     | 
| 
       356 
357 
     | 
    
         
             
                  ::Hash[hash.map do |key, value|
         
     | 
| 
      
 358 
     | 
    
         
            +
                    if (key.is_a?(String) || key.is_a?(Symbol)) && key.to_s.include?(NULL_BYTE)
         
     | 
| 
      
 359 
     | 
    
         
            +
                      raise Error::ExtJSONParseError, "Hash key cannot contain a null byte: #{key}"
         
     | 
| 
      
 360 
     | 
    
         
            +
                    end
         
     | 
| 
       357 
361 
     | 
    
         
             
                    [key, parse_obj(value, **options)]
         
     | 
| 
       358 
362 
     | 
    
         
             
                  end]
         
     | 
| 
       359 
363 
     | 
    
         
             
                end
         
     | 
| 
         @@ -371,5 +375,14 @@ module BSON 
     | 
|
| 
       371 
375 
     | 
    
         
             
                module_function def create_regexp(pattern, options)
         
     | 
| 
       372 
376 
     | 
    
         
             
                  Regexp::Raw.new(pattern, options)
         
     | 
| 
       373 
377 
     | 
    
         
             
                end
         
     | 
| 
      
 378 
     | 
    
         
            +
             
     | 
| 
      
 379 
     | 
    
         
            +
                module_function def dbref?(hash)
         
     | 
| 
      
 380 
     | 
    
         
            +
                  if db = hash.key?('$db')
         
     | 
| 
      
 381 
     | 
    
         
            +
                    unless db.is_a?(String)
         
     | 
| 
      
 382 
     | 
    
         
            +
                      return false
         
     | 
| 
      
 383 
     | 
    
         
            +
                    end
         
     | 
| 
      
 384 
     | 
    
         
            +
                  end
         
     | 
| 
      
 385 
     | 
    
         
            +
                  return hash['$ref']&.is_a?(String) && hash.key?('$id')
         
     | 
| 
      
 386 
     | 
    
         
            +
                end
         
     | 
| 
       374 
387 
     | 
    
         
             
              end
         
     | 
| 
       375 
388 
     | 
    
         
             
            end
         
     | 
    
        data/lib/bson/false_class.rb
    CHANGED
    
    | 
         @@ -1,3 +1,4 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
       1 
2 
     | 
    
         
             
            # Copyright (C) 2009-2020 MongoDB Inc.
         
     | 
| 
       2 
3 
     | 
    
         
             
            #
         
     | 
| 
       3 
4 
     | 
    
         
             
            # Licensed under the Apache License, Version 2.0 (the "License");
         
     | 
| 
         @@ -25,7 +26,7 @@ module BSON 
     | 
|
| 
       25 
26 
     | 
    
         
             
                # A false value in the BSON spec is 0x00.
         
     | 
| 
       26 
27 
     | 
    
         
             
                #
         
     | 
| 
       27 
28 
     | 
    
         
             
                # @since 2.0.0
         
     | 
| 
       28 
     | 
    
         
            -
                FALSE_BYTE = 0.chr 
     | 
| 
      
 29 
     | 
    
         
            +
                FALSE_BYTE = String.new(0.chr, encoding: BINARY).freeze
         
     | 
| 
       29 
30 
     | 
    
         | 
| 
       30 
31 
     | 
    
         
             
                # The BSON type for false values is the general boolean type of 0x08.
         
     | 
| 
       31 
32 
     | 
    
         
             
                #
         
     | 
    
        data/lib/bson/float.rb
    CHANGED
    
    | 
         @@ -1,3 +1,4 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
       1 
2 
     | 
    
         
             
            # Copyright (C) 2009-2020 MongoDB Inc.
         
     | 
| 
       2 
3 
     | 
    
         
             
            #
         
     | 
| 
       3 
4 
     | 
    
         
             
            # Licensed under the Apache License, Version 2.0 (the "License");
         
     | 
| 
         @@ -15,7 +16,7 @@ 
     | 
|
| 
       15 
16 
     | 
    
         
             
            module BSON
         
     | 
| 
       16 
17 
     | 
    
         | 
| 
       17 
18 
     | 
    
         
             
              # Injects behaviour for encoding and decoding floating point values
         
     | 
| 
       18 
     | 
    
         
            -
              # to and from  
     | 
| 
      
 19 
     | 
    
         
            +
              # to and from raw bytes as specified by the BSON spec.
         
     | 
| 
       19 
20 
     | 
    
         
             
              #
         
     | 
| 
       20 
21 
     | 
    
         
             
              # @see http://bsonspec.org/#/specification
         
     | 
| 
       21 
22 
     | 
    
         
             
              #
         
     | 
| 
         @@ -25,12 +26,12 @@ module BSON 
     | 
|
| 
       25 
26 
     | 
    
         
             
                # A floating point is type 0x01 in the BSON spec.
         
     | 
| 
       26 
27 
     | 
    
         
             
                #
         
     | 
| 
       27 
28 
     | 
    
         
             
                # @since 2.0.0
         
     | 
| 
       28 
     | 
    
         
            -
                BSON_TYPE = 1.chr 
     | 
| 
      
 29 
     | 
    
         
            +
                BSON_TYPE = ::String.new(1.chr, encoding: BINARY).freeze
         
     | 
| 
       29 
30 
     | 
    
         | 
| 
       30 
31 
     | 
    
         
             
                # The pack directive is for 8 byte floating points.
         
     | 
| 
       31 
32 
     | 
    
         
             
                #
         
     | 
| 
       32 
33 
     | 
    
         
             
                # @since 2.0.0
         
     | 
| 
       33 
     | 
    
         
            -
                PACK = "E" 
     | 
| 
      
 34 
     | 
    
         
            +
                PACK = "E"
         
     | 
| 
       34 
35 
     | 
    
         | 
| 
       35 
36 
     | 
    
         
             
                # Get the floating point as encoded BSON.
         
     | 
| 
       36 
37 
     | 
    
         
             
                #
         
     | 
| 
         @@ -57,36 +58,24 @@ module BSON 
     | 
|
| 
       57 
58 
     | 
    
         
             
                #
         
     | 
| 
       58 
59 
     | 
    
         
             
                # @return [ Hash | Float ] The extended json representation.
         
     | 
| 
       59 
60 
     | 
    
         
             
                def as_extended_json(**options)
         
     | 
| 
       60 
     | 
    
         
            -
                   
     | 
| 
       61 
     | 
    
         
            -
             
     | 
| 
       62 
     | 
    
         
            -
             
     | 
| 
       63 
     | 
    
         
            -
             
     | 
| 
       64 
     | 
    
         
            -
             
     | 
| 
      
 61 
     | 
    
         
            +
                  if infinite? == 1
         
     | 
| 
      
 62 
     | 
    
         
            +
                    { '$numberDouble' => 'Infinity' }
         
     | 
| 
      
 63 
     | 
    
         
            +
                  elsif infinite? == -1
         
     | 
| 
      
 64 
     | 
    
         
            +
                    { '$numberDouble' => '-Infinity' }
         
     | 
| 
      
 65 
     | 
    
         
            +
                  elsif nan?
         
     | 
| 
      
 66 
     | 
    
         
            +
                    { '$numberDouble' => 'NaN' }
         
     | 
| 
      
 67 
     | 
    
         
            +
                  elsif options[:mode] == :relaxed || options[:mode] == :legacy
         
     | 
| 
      
 68 
     | 
    
         
            +
                    self
         
     | 
| 
      
 69 
     | 
    
         
            +
                  elsif BSON::Environment.jruby? && abs > 1e15
         
     | 
| 
      
 70 
     | 
    
         
            +
                    # Hack to make bson corpus spec tests pass.
         
     | 
| 
      
 71 
     | 
    
         
            +
                    # JRuby serializes -1.2345678901234568e+18 as
         
     | 
| 
      
 72 
     | 
    
         
            +
                    # -1234567890123456770.0, which is valid but differs from MRI
         
     | 
| 
      
 73 
     | 
    
         
            +
                    # serialization. Extended JSON spec does not define precise
         
     | 
| 
      
 74 
     | 
    
         
            +
                    # stringification of floats.
         
     | 
| 
      
 75 
     | 
    
         
            +
                    # https://jira.mongodb.org/browse/SPEC-1536
         
     | 
| 
      
 76 
     | 
    
         
            +
                    { '$numberDouble' => ('%.17g' % to_s).upcase }
         
     | 
| 
       65 
77 
     | 
    
         
             
                  else
         
     | 
| 
       66 
     | 
    
         
            -
                     
     | 
| 
       67 
     | 
    
         
            -
                      {'$numberDouble' => 'NaN'}
         
     | 
| 
       68 
     | 
    
         
            -
                    else
         
     | 
| 
       69 
     | 
    
         
            -
                      if options[:mode] == :relaxed || options[:mode] == :legacy
         
     | 
| 
       70 
     | 
    
         
            -
                        self
         
     | 
| 
       71 
     | 
    
         
            -
                      else
         
     | 
| 
       72 
     | 
    
         
            -
                        value = if BSON::Environment.jruby?
         
     | 
| 
       73 
     | 
    
         
            -
                          # Hack to make bson corpus spec tests pass.
         
     | 
| 
       74 
     | 
    
         
            -
                          # JRuby serializes -1.2345678901234568e+18 as
         
     | 
| 
       75 
     | 
    
         
            -
                          # -1234567890123456770.0, which is valid but differs from MRI
         
     | 
| 
       76 
     | 
    
         
            -
                          # serialization. Extended JSON spec does not define precise
         
     | 
| 
       77 
     | 
    
         
            -
                          # stringification of floats.
         
     | 
| 
       78 
     | 
    
         
            -
                          # https://jira.mongodb.org/browse/SPEC-1536
         
     | 
| 
       79 
     | 
    
         
            -
                          if abs > 1e15
         
     | 
| 
       80 
     | 
    
         
            -
                            '%.17g' % to_s
         
     | 
| 
       81 
     | 
    
         
            -
                          else
         
     | 
| 
       82 
     | 
    
         
            -
                            to_s
         
     | 
| 
       83 
     | 
    
         
            -
                          end
         
     | 
| 
       84 
     | 
    
         
            -
                        else
         
     | 
| 
       85 
     | 
    
         
            -
                          to_s
         
     | 
| 
       86 
     | 
    
         
            -
                        end
         
     | 
| 
       87 
     | 
    
         
            -
                        {'$numberDouble' => value.upcase}
         
     | 
| 
       88 
     | 
    
         
            -
                      end
         
     | 
| 
       89 
     | 
    
         
            -
                    end
         
     | 
| 
      
 78 
     | 
    
         
            +
                    { '$numberDouble' => to_s.upcase }
         
     | 
| 
       90 
79 
     | 
    
         
             
                  end
         
     | 
| 
       91 
80 
     | 
    
         
             
                end
         
     | 
| 
       92 
81 
     | 
    
         | 
    
        data/lib/bson/hash.rb
    CHANGED
    
    | 
         @@ -1,3 +1,4 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
       1 
2 
     | 
    
         
             
            # Copyright (C) 2009-2020 MongoDB Inc.
         
     | 
| 
       2 
3 
     | 
    
         
             
            #
         
     | 
| 
       3 
4 
     | 
    
         
             
            # Licensed under the Apache License, Version 2.0 (the "License");
         
     | 
| 
         @@ -25,7 +26,7 @@ module BSON 
     | 
|
| 
       25 
26 
     | 
    
         
             
                # A hash, also called an embedded document, is type 0x03 in the BSON spec.
         
     | 
| 
       26 
27 
     | 
    
         
             
                #
         
     | 
| 
       27 
28 
     | 
    
         
             
                # @since 2.0.0
         
     | 
| 
       28 
     | 
    
         
            -
                BSON_TYPE = 3.chr 
     | 
| 
      
 29 
     | 
    
         
            +
                BSON_TYPE = ::String.new(3.chr, encoding: BINARY).freeze
         
     | 
| 
       29 
30 
     | 
    
         | 
| 
       30 
31 
     | 
    
         
             
                # Get the hash as encoded BSON.
         
     | 
| 
       31 
32 
     | 
    
         
             
                #
         
     | 
| 
         @@ -70,7 +71,7 @@ module BSON 
     | 
|
| 
       70 
71 
     | 
    
         
             
                # @example Convert the hash to a normalized value.
         
     | 
| 
       71 
72 
     | 
    
         
             
                #   hash.to_bson_normalized_value
         
     | 
| 
       72 
73 
     | 
    
         
             
                #
         
     | 
| 
       73 
     | 
    
         
            -
                # @return [ BSON::Document ] The  
     | 
| 
      
 74 
     | 
    
         
            +
                # @return [ BSON::Document ] The normalized hash.
         
     | 
| 
       74 
75 
     | 
    
         
             
                #
         
     | 
| 
       75 
76 
     | 
    
         
             
                # @since 3.0.0
         
     | 
| 
       76 
77 
     | 
    
         
             
                def to_bson_normalized_value
         
     | 
| 
         @@ -88,9 +89,7 @@ module BSON 
     | 
|
| 
       88 
89 
     | 
    
         
             
                #
         
     | 
| 
       89 
90 
     | 
    
         
             
                # @return [ Hash ] This hash converted to extended json representation.
         
     | 
| 
       90 
91 
     | 
    
         
             
                def as_extended_json(**options)
         
     | 
| 
       91 
     | 
    
         
            -
                   
     | 
| 
       92 
     | 
    
         
            -
                    [key, value.as_extended_json(**options)]
         
     | 
| 
       93 
     | 
    
         
            -
                  end]
         
     | 
| 
      
 92 
     | 
    
         
            +
                  transform_values { |value| value.as_extended_json(**options) }
         
     | 
| 
       94 
93 
     | 
    
         
             
                end
         
     | 
| 
       95 
94 
     | 
    
         | 
| 
       96 
95 
     | 
    
         
             
                module ClassMethods
         
     | 
| 
         @@ -101,7 +100,7 @@ module BSON 
     | 
|
| 
       101 
100 
     | 
    
         
             
                  #
         
     | 
| 
       102 
101 
     | 
    
         
             
                  # @option options [ nil | :bson ] :mode Decoding mode to use.
         
     | 
| 
       103 
102 
     | 
    
         
             
                  #
         
     | 
| 
       104 
     | 
    
         
            -
                  # @return [  
     | 
| 
      
 103 
     | 
    
         
            +
                  # @return [ Hash ] The decoded hash.
         
     | 
| 
       105 
104 
     | 
    
         
             
                  #
         
     | 
| 
       106 
105 
     | 
    
         
             
                  # @see http://bsonspec.org/#/specification
         
     | 
| 
       107 
106 
     | 
    
         
             
                  #
         
     | 
| 
         @@ -129,6 +128,16 @@ module BSON 
     | 
|
| 
       129 
128 
     | 
    
         
             
                      if actual_byte_size != expected_byte_size
         
     | 
| 
       130 
129 
     | 
    
         
             
                        raise Error::BSONDecodeError, "Expected hash to take #{expected_byte_size} bytes but it took #{actual_byte_size} bytes"
         
     | 
| 
       131 
130 
     | 
    
         
             
                      end
         
     | 
| 
      
 131 
     | 
    
         
            +
             
     | 
| 
      
 132 
     | 
    
         
            +
                      if hash['$ref'] && hash['$id']
         
     | 
| 
      
 133 
     | 
    
         
            +
                        # We're doing implicit decoding here. If the document is an invalid
         
     | 
| 
      
 134 
     | 
    
         
            +
                        # dbref, we should decode it as a BSON::Document.
         
     | 
| 
      
 135 
     | 
    
         
            +
                        begin
         
     | 
| 
      
 136 
     | 
    
         
            +
                          hash = DBRef.new(hash)
         
     | 
| 
      
 137 
     | 
    
         
            +
                        rescue ArgumentError
         
     | 
| 
      
 138 
     | 
    
         
            +
                        end
         
     | 
| 
      
 139 
     | 
    
         
            +
                      end
         
     | 
| 
      
 140 
     | 
    
         
            +
             
     | 
| 
       132 
141 
     | 
    
         
             
                      hash
         
     | 
| 
       133 
142 
     | 
    
         
             
                    end
         
     | 
| 
       134 
143 
     | 
    
         
             
                  end
         
     | 
    
        data/lib/bson/int32.rb
    CHANGED
    
    | 
         @@ -1,3 +1,4 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
       1 
2 
     | 
    
         
             
            # Copyright (C) 2009-2020 MongoDB Inc.
         
     | 
| 
       2 
3 
     | 
    
         
             
            #
         
     | 
| 
       3 
4 
     | 
    
         
             
            # Licensed under the Apache License, Version 2.0 (the "License");
         
     | 
| 
         @@ -24,7 +25,7 @@ module BSON 
     | 
|
| 
       24 
25 
     | 
    
         
             
                # A boolean is type 0x08 in the BSON spec.
         
     | 
| 
       25 
26 
     | 
    
         
             
                #
         
     | 
| 
       26 
27 
     | 
    
         
             
                # @since 2.0.0
         
     | 
| 
       27 
     | 
    
         
            -
                BSON_TYPE = 16.chr 
     | 
| 
      
 28 
     | 
    
         
            +
                BSON_TYPE = ::String.new(16.chr, encoding: BINARY).freeze
         
     | 
| 
       28 
29 
     | 
    
         | 
| 
       29 
30 
     | 
    
         
             
                # The number of bytes constant.
         
     | 
| 
       30 
31 
     | 
    
         
             
                #
         
     | 
| 
         @@ -34,7 +35,7 @@ module BSON 
     | 
|
| 
       34 
35 
     | 
    
         
             
                # Constant for the int 32 pack directive.
         
     | 
| 
       35 
36 
     | 
    
         
             
                #
         
     | 
| 
       36 
37 
     | 
    
         
             
                # @since 2.0.0
         
     | 
| 
       37 
     | 
    
         
            -
                PACK = "l<" 
     | 
| 
      
 38 
     | 
    
         
            +
                PACK = "l<"
         
     | 
| 
       38 
39 
     | 
    
         | 
| 
       39 
40 
     | 
    
         
             
                # Deserialize an Integer from BSON.
         
     | 
| 
       40 
41 
     | 
    
         
             
                #
         
     | 
    
        data/lib/bson/int64.rb
    CHANGED
    
    | 
         @@ -1,3 +1,4 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
       1 
2 
     | 
    
         
             
            # Copyright (C) 2009-2020 MongoDB Inc.
         
     | 
| 
       2 
3 
     | 
    
         
             
            #
         
     | 
| 
       3 
4 
     | 
    
         
             
            # Licensed under the Apache License, Version 2.0 (the "License");
         
     | 
| 
         @@ -24,12 +25,12 @@ module BSON 
     | 
|
| 
       24 
25 
     | 
    
         
             
                # A boolean is type 0x08 in the BSON spec.
         
     | 
| 
       25 
26 
     | 
    
         
             
                #
         
     | 
| 
       26 
27 
     | 
    
         
             
                # @since 2.0.0
         
     | 
| 
       27 
     | 
    
         
            -
                BSON_TYPE = 18.chr 
     | 
| 
      
 28 
     | 
    
         
            +
                BSON_TYPE = ::String.new(18.chr, encoding: BINARY).freeze
         
     | 
| 
       28 
29 
     | 
    
         | 
| 
       29 
30 
     | 
    
         
             
                # Constant for the int 64 pack directive.
         
     | 
| 
       30 
31 
     | 
    
         
             
                #
         
     | 
| 
       31 
32 
     | 
    
         
             
                # @since 2.0.0
         
     | 
| 
       32 
     | 
    
         
            -
                PACK = "q<" 
     | 
| 
      
 33 
     | 
    
         
            +
                PACK = "q<"
         
     | 
| 
       33 
34 
     | 
    
         | 
| 
       34 
35 
     | 
    
         
             
                # Deserialize an Integer from BSON.
         
     | 
| 
       35 
36 
     | 
    
         
             
                #
         
     | 
    
        data/lib/bson/integer.rb
    CHANGED
    
    | 
         @@ -1,3 +1,4 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
       1 
2 
     | 
    
         
             
            # Copyright (C) 2009-2020 MongoDB Inc.
         
     | 
| 
       2 
3 
     | 
    
         
             
            #
         
     | 
| 
       3 
4 
     | 
    
         
             
            # Licensed under the Apache License, Version 2.0 (the "License");
         
     | 
| 
         @@ -45,13 +46,13 @@ module BSON 
     | 
|
| 
       45 
46 
     | 
    
         
             
                # The BSON index size.
         
     | 
| 
       46 
47 
     | 
    
         
             
                #
         
     | 
| 
       47 
48 
     | 
    
         
             
                # @since 2.0.0
         
     | 
| 
       48 
     | 
    
         
            -
                BSON_INDEX_SIZE = 1024 
     | 
| 
      
 49 
     | 
    
         
            +
                BSON_INDEX_SIZE = 1024
         
     | 
| 
       49 
50 
     | 
    
         | 
| 
       50 
51 
     | 
    
         
             
                # A hash of index values for array optimization.
         
     | 
| 
       51 
52 
     | 
    
         
             
                #
         
     | 
| 
       52 
53 
     | 
    
         
             
                # @since 2.0.0
         
     | 
| 
       53 
54 
     | 
    
         
             
                BSON_ARRAY_INDEXES = ::Array.new(BSON_INDEX_SIZE) do |i|
         
     | 
| 
       54 
     | 
    
         
            -
                  (i.to_s. 
     | 
| 
      
 55 
     | 
    
         
            +
                  (i.to_s.b << NULL_BYTE).freeze
         
     | 
| 
       55 
56 
     | 
    
         
             
                end.freeze
         
     | 
| 
       56 
57 
     | 
    
         | 
| 
       57 
58 
     | 
    
         
             
                # Is this integer a valid BSON 32 bit value?
         
     | 
    
        data/lib/bson/json.rb
    CHANGED
    
    
    
        data/lib/bson/max_key.rb
    CHANGED
    
    | 
         @@ -1,3 +1,4 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
       1 
2 
     | 
    
         
             
            # Copyright (C) 2009-2020 MongoDB Inc.
         
     | 
| 
       2 
3 
     | 
    
         
             
            #
         
     | 
| 
       3 
4 
     | 
    
         
             
            # Licensed under the Apache License, Version 2.0 (the "License");
         
     | 
| 
         @@ -28,12 +29,12 @@ module BSON 
     | 
|
| 
       28 
29 
     | 
    
         
             
                # A $maxKey is type 0x7F in the BSON spec.
         
     | 
| 
       29 
30 
     | 
    
         
             
                #
         
     | 
| 
       30 
31 
     | 
    
         
             
                # @since 2.0.0
         
     | 
| 
       31 
     | 
    
         
            -
                BSON_TYPE = 127.chr 
     | 
| 
      
 32 
     | 
    
         
            +
                BSON_TYPE = ::String.new(127.chr, encoding: BINARY).freeze
         
     | 
| 
       32 
33 
     | 
    
         | 
| 
       33 
34 
     | 
    
         
             
                # Constant for always evaluating greater in a comparison.
         
     | 
| 
       34 
35 
     | 
    
         
             
                #
         
     | 
| 
       35 
36 
     | 
    
         
             
                # @since 2.0.0
         
     | 
| 
       36 
     | 
    
         
            -
                GREATER = 1 
     | 
| 
      
 37 
     | 
    
         
            +
                GREATER = 1
         
     | 
| 
       37 
38 
     | 
    
         | 
| 
       38 
39 
     | 
    
         
             
                # When comparing a max key with any other object, the max key will always
         
     | 
| 
       39 
40 
     | 
    
         
             
                # be greater.
         
     | 
    
        data/lib/bson/min_key.rb
    CHANGED
    
    | 
         @@ -1,3 +1,4 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
       1 
2 
     | 
    
         
             
            # Copyright (C) 2009-2020 MongoDB Inc.
         
     | 
| 
       2 
3 
     | 
    
         
             
            #
         
     | 
| 
       3 
4 
     | 
    
         
             
            # Licensed under the Apache License, Version 2.0 (the "License");
         
     | 
| 
         @@ -28,12 +29,12 @@ module BSON 
     | 
|
| 
       28 
29 
     | 
    
         
             
                # A $minKey is type 0xFF in the BSON spec.
         
     | 
| 
       29 
30 
     | 
    
         
             
                #
         
     | 
| 
       30 
31 
     | 
    
         
             
                # @since 2.0.0
         
     | 
| 
       31 
     | 
    
         
            -
                BSON_TYPE = 255.chr 
     | 
| 
      
 32 
     | 
    
         
            +
                BSON_TYPE = ::String.new(255.chr, encoding: BINARY).freeze
         
     | 
| 
       32 
33 
     | 
    
         | 
| 
       33 
34 
     | 
    
         
             
                # Constant for always evaluating lesser in a comparison.
         
     | 
| 
       34 
35 
     | 
    
         
             
                #
         
     | 
| 
       35 
36 
     | 
    
         
             
                # @since 2.0.0
         
     | 
| 
       36 
     | 
    
         
            -
                LESSER = -1 
     | 
| 
      
 37 
     | 
    
         
            +
                LESSER = -1
         
     | 
| 
       37 
38 
     | 
    
         | 
| 
       38 
39 
     | 
    
         
             
                # When comparing a min key with any other object, the min key will always
         
     | 
| 
       39 
40 
     | 
    
         
             
                # be lesser.
         
     | 
    
        data/lib/bson/nil_class.rb
    CHANGED
    
    | 
         @@ -1,3 +1,4 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
       1 
2 
     | 
    
         
             
            # Copyright (C) 2009-2020 MongoDB Inc.
         
     | 
| 
       2 
3 
     | 
    
         
             
            #
         
     | 
| 
       3 
4 
     | 
    
         
             
            # Licensed under the Apache License, Version 2.0 (the "License");
         
     | 
| 
         @@ -26,7 +27,7 @@ module BSON 
     | 
|
| 
       26 
27 
     | 
    
         
             
                # A nil is type 0x0A in the BSON spec.
         
     | 
| 
       27 
28 
     | 
    
         
             
                #
         
     | 
| 
       28 
29 
     | 
    
         
             
                # @since 2.0.0
         
     | 
| 
       29 
     | 
    
         
            -
                BSON_TYPE = 10.chr 
     | 
| 
      
 30 
     | 
    
         
            +
                BSON_TYPE = ::String.new(10.chr, encoding: BINARY).freeze
         
     | 
| 
       30 
31 
     | 
    
         | 
| 
       31 
32 
     | 
    
         
             
                module ClassMethods
         
     | 
| 
       32 
33 
     | 
    
         | 
    
        data/lib/bson/object.rb
    CHANGED
    
    
    
        data/lib/bson/object_id.rb
    CHANGED
    
    | 
         @@ -1,3 +1,4 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
       1 
2 
     | 
    
         
             
            # Copyright (C) 2009-2020 MongoDB Inc.
         
     | 
| 
       2 
3 
     | 
    
         
             
            #
         
     | 
| 
       3 
4 
     | 
    
         
             
            # Licensed under the Apache License, Version 2.0 (the "License");
         
     | 
| 
         @@ -30,7 +31,7 @@ module BSON 
     | 
|
| 
       30 
31 
     | 
    
         
             
                # A object_id is type 0x07 in the BSON spec.
         
     | 
| 
       31 
32 
     | 
    
         
             
                #
         
     | 
| 
       32 
33 
     | 
    
         
             
                # @since 2.0.0
         
     | 
| 
       33 
     | 
    
         
            -
                BSON_TYPE = 7.chr 
     | 
| 
      
 34 
     | 
    
         
            +
                BSON_TYPE = ::String.new(7.chr, encoding: BINARY).freeze
         
     | 
| 
       34 
35 
     | 
    
         | 
| 
       35 
36 
     | 
    
         
             
                # Check equality of the object id with another object.
         
     | 
| 
       36 
37 
     | 
    
         
             
                #
         
     | 
| 
         @@ -112,7 +113,7 @@ module BSON 
     | 
|
| 
       112 
113 
     | 
    
         
             
                #
         
     | 
| 
       113 
114 
     | 
    
         
             
                # @since 2.0.0
         
     | 
| 
       114 
115 
     | 
    
         
             
                def generation_time
         
     | 
| 
       115 
     | 
    
         
            -
                  ::Time.at(generate_data. 
     | 
| 
      
 116 
     | 
    
         
            +
                  ::Time.at(generate_data.unpack1("N")).utc
         
     | 
| 
       116 
117 
     | 
    
         
             
                end
         
     | 
| 
       117 
118 
     | 
    
         
             
                alias :to_time :generation_time
         
     | 
| 
       118 
119 
     | 
    
         | 
| 
         @@ -352,7 +353,7 @@ module BSON 
     | 
|
| 
       352 
353 
     | 
    
         
             
                  # @since 2.0.0
         
     | 
| 
       353 
354 
     | 
    
         
             
                  def initialize
         
     | 
| 
       354 
355 
     | 
    
         
             
                    @counter = rand(0x1000000)
         
     | 
| 
       355 
     | 
    
         
            -
                    @machine_id = Digest::MD5.digest(Socket.gethostname). 
     | 
| 
      
 356 
     | 
    
         
            +
                    @machine_id = Digest::MD5.digest(Socket.gethostname).unpack1("N")
         
     | 
| 
       356 
357 
     | 
    
         
             
                    @mutex = Mutex.new
         
     | 
| 
       357 
358 
     | 
    
         
             
                  end
         
     | 
| 
       358 
359 
     | 
    
         | 
    
        data/lib/bson/open_struct.rb
    CHANGED