FIX: Use safe navigation operator when looking for avatar URL

FIX: Use safe navigation operator when looking for avatar URL

From 4e2cc9caf0472ab5f3674556fddbf65eabb2fb3f Mon Sep 17 00:00:00 2001
From: David Taylor <david@taylorhq.com>
Date: Mon, 3 Dec 2018 17:28:21 +0000
Subject: [PATCH] FIX: Use safe navigation operator when looking for avatar URL


diff --git a/lib/auth/managed_authenticator.rb b/lib/auth/managed_authenticator.rb
index 590efaa..9df6151 100644
--- a/lib/auth/managed_authenticator.rb
+++ b/lib/auth/managed_authenticator.rb
@@ -94,7 +94,7 @@ class Auth::ManagedAuthenticator < Auth::Authenticator
   def after_create_account(user, auth)
     data = auth[:extra_data]
     create_association!(data.merge(user: user))
-    retrieve_avatar(user, data["info"]["image"])
+    retrieve_avatar(user, data&.[]("info")&.[]("image"))
   end
 
   def retrieve_avatar(user, url)

GitHub

1 Like

Does Hash#dig work here? It may not if this is a weird OmniAuth CrazyHashMash object that does not implement it.

2 Likes

Switched to #dig and added some tests in FIX: Improve avatar loading, and add tests · discourse/discourse@e117deb · GitHub

1 Like