Skip to content

Commit 9560a4e

Browse files
committed
Add UnsupportedError for unsupported features and update raise_on_duplicate_keys! method
1 parent 2125443 commit 9560a4e

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

lib/jwt/encoded_token.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ def initialize(jwt)
6262
#
6363
# @return [self]
6464
# @raise [JWT::DuplicateKeyError] if duplicate keys are found during subsequent parsing.
65+
# @raise [JWT::UnsupportedError] if the JSON gem version does not support duplicate key detection.
6566
def raise_on_duplicate_keys!
67+
raise JWT::UnsupportedError, 'Duplicate key detection requires JSON gem >= 2.13.0' unless JSON.supports_duplicate_key_detection?
68+
6669
@allow_duplicate_keys = false
6770
self
6871
end

lib/jwt/error.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,7 @@ class JWKError < DecodeError; end
5555
# The DuplicateKeyError class is raised when a JWT contains duplicate keys in the header or payload.
5656
# @see https://datatracker.ietf.org/doc/html/rfc7519#section-4 RFC 7519 Section 4
5757
class DuplicateKeyError < DecodeError; end
58+
59+
# The UnsupportedError class is raised when a feature is not supported by the current environment.
60+
class UnsupportedError < StandardError; end
5861
end

lib/jwt/json.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ def parse(data, allow_duplicate_keys: true)
2121
raise
2222
end
2323

24-
private
25-
2624
def supports_duplicate_key_detection?
2725
return @supports_duplicate_key_detection if defined?(@supports_duplicate_key_detection)
2826

0 commit comments

Comments
 (0)