Skip to content

Commit e1977a1

Browse files
committed
Fix GitHub's avatar URL
At the moment, the URL is being composed and modified with the use of string composition. This causes issues, if the URL returned by GitHub slightly differs from the time developer initially had a look into it. In our case, the URL from GitHub has two query parameters in it, whilst the codebase only expected one. This change will take all of these parameters and only set the one we care about, whilst leaving others intact and carry on with the full URL. Fixes #1489 Signed-off-by: Rafal Proszowski <paroxp@gmail.com>
1 parent d7cc951 commit e1977a1

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

lib/models/user.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,11 @@ module.exports = function (sequelize, DataTypes) {
115115
else photo += '?size=bigger'
116116
break
117117
case 'github':
118-
if (profile.photos && profile.photos[0]) photo = profile.photos[0].value.replace('?', '')
119-
else photo = 'https://avatars.githubusercontent.com/u/' + profile.id
120-
if (bigger) photo += '?s=400'
121-
else photo += '?s=96'
118+
const photoURL = new URL(profile.photos && profile.photos[0]
119+
? profile.photos[0].value
120+
: `https://avatars.githubusercontent.com/u/${profile.id}`)
121+
photoURL.searchParams.set('s', bigger ? 400 : 96)
122+
photo = photoURL.toString()
122123
break
123124
case 'gitlab':
124125
photo = profile.avatarUrl

0 commit comments

Comments
 (0)