Skip to content

Commit 5bc399d

Browse files
Merge pull request rails#46612 from ianks/messages-parse-fix
Peek before attempting to deserialize `ActiveSupport::Messages::Metadata` with JSON
2 parents ebbf66d + d489306 commit 5bc399d

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

activesupport/lib/active_support/messages/metadata.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ def pick_expiry(expires_at, expires_in)
3737
end
3838

3939
def extract_metadata(message)
40-
data = JSON.decode(message) rescue nil
40+
begin
41+
data = JSON.decode(message) if message.start_with?("{")
42+
rescue ::JSON::JSONError
43+
end
4144

4245
if data.is_a?(Hash) && data.key?("_rails")
4346
new(decode(data["_rails"]["message"]), data["_rails"]["exp"], data["_rails"]["pur"])

0 commit comments

Comments
 (0)