Skip to content

Commit

Permalink
Merge pull request #16441 from hellohublot/16354_getSmallSizeAvatar_c…
Browse files Browse the repository at this point in the history
…loudfront

Fix getSmallSizeAvatar to block url is not from cloudfront

(cherry picked from commit 4350683)
  • Loading branch information
AndrewGable authored and OSBotify committed Mar 24, 2023
1 parent 76f49ba commit bc77d3c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/CONST.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import lodashGet from 'lodash/get';
import Config from 'react-native-config';
import * as Url from './libs/Url';

const CLOUDFRONT_URL = 'https://d2k5nsl2zxldvw.cloudfront.net';
const CLOUDFRONT_DOMAIN = 'cloudfront.net';
const CLOUDFRONT_URL = `https://d2k5nsl2zxldvw.${CLOUDFRONT_DOMAIN}`;
const ACTIVE_EXPENSIFY_URL = Url.addTrailingForwardSlash(lodashGet(Config, 'NEW_EXPENSIFY_URL', 'https://new.expensify.com'));
const USE_EXPENSIFY_URL = 'https://use.expensify.com';
const PLATFORM_OS_MACOS = 'Mac OS';
Expand Down Expand Up @@ -289,6 +290,7 @@ const CONST = {
GOOGLE_MEET_URL_ANDROID: 'https://meet.google.com',
DEEPLINK_BASE_URL: 'new-expensify://',
PDF_VIEWER_URL: '/pdf/web/viewer.html',
CLOUDFRONT_DOMAIN_REGEX: /^https:\/\/\w+\.cloudfront\.net/i,
EXPENSIFY_ICON_URL: `${CLOUDFRONT_URL}/images/favicon-2019.png`,
CONCIERGE_ICON_URL: `${CLOUDFRONT_URL}/images/icons/concierge_2022.png`,
UPWORK_URL: 'https://github.com/Expensify/App/issues?q=is%3Aopen+is%3Aissue+label%3A%22Help+Wanted%22',
Expand Down
5 changes: 5 additions & 0 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,11 @@ function getSmallSizeAvatar(avatarURL, login) {
return source;
}

// Because other urls than CloudFront do not support dynamic image sizing (_SIZE suffix), the current source is already what we want to use here.
if (!CONST.CLOUDFRONT_DOMAIN_REGEX.test(source)) {
return source;
}

// If image source already has _128 at the end, the given avatar URL is already what we want to use here.
const lastPeriodIndex = source.lastIndexOf('.');
if (source.substring(lastPeriodIndex - 4, lastPeriodIndex) === '_128') {
Expand Down

0 comments on commit bc77d3c

Please sign in to comment.