Skip to content

Commit 9bb59d1

Browse files
authored
fix: encode hash on getUserPhoto (#3408)
* fix userPrincipleName/mail encoding * use encodeUriComponent
1 parent e49591d commit 9bb59d1

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

packages/mgt-components/src/graph/graph.people.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,9 @@ export const getEmailFromGraphEntity = (entity: IDynamicPerson): string => {
218218

219219
if (user?.mail) {
220220
return extractEmailAddress(user.mail);
221-
} else if (person.scoredEmailAddresses?.length) {
221+
} else if (person?.scoredEmailAddresses?.length) {
222222
return extractEmailAddress(person.scoredEmailAddresses[0].address);
223-
} else if (contact.emailAddresses?.length) {
223+
} else if (contact?.emailAddresses?.length) {
224224
return extractEmailAddress(contact.emailAddresses[0].address);
225225
}
226226
return null;
@@ -244,7 +244,7 @@ export const findContactsByEmail = async (graph: IGraph, email: string): Promise
244244
}
245245
}
246246

247-
const encodedEmail = `${email.replace(/#/g, '%2523')}`;
247+
const encodedEmail = encodeURIComponent(email);
248248

249249
const result = (await graph
250250
.api('/me/contacts')

packages/mgt-components/src/graph/graph.photos.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ export const getUserPhoto = async (graph: IGraph, userId: string): Promise<strin
120120
let cache: CacheStore<CachePhoto>;
121121
let photoDetails: CachePhoto;
122122

123+
const encodedUser = encodeURIComponent(userId);
124+
123125
if (getIsPhotosCacheEnabled()) {
124126
cache = CacheService.getCache<CachePhoto>(schemas.photos, schemas.photos.stores.users);
125127
photoDetails = await cache.getValue(userId);
@@ -144,7 +146,7 @@ export const getUserPhoto = async (graph: IGraph, userId: string): Promise<strin
144146
}
145147
}
146148
// if there is a photo in the cache, we got here because it was stale
147-
photoDetails = photoDetails || (await getPhotoForResource(graph, `users/${userId}`, anyUserValidPhotoScopes));
149+
photoDetails = photoDetails || (await getPhotoForResource(graph, `users/${encodedUser}`, anyUserValidPhotoScopes));
148150
if (getIsPhotosCacheEnabled() && photoDetails) {
149151
await cache.putValue(userId, photoDetails);
150152
}

packages/mgt-components/src/graph/graph.user.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ export const findUsers = async (graph: IGraph, query: string, top = 10, userFilt
417417
}
418418
}
419419

420-
const encodedQuery = `${query.replace(/#/g, '%2523')}`;
420+
const encodedQuery = encodeURIComponent(query);
421421
const graphBuilder = graph
422422
.api('users')
423423
.search(`"displayName:${encodedQuery}" OR "mail:${encodedQuery}" OR "userPrincipalName:${encodedQuery}"`)

0 commit comments

Comments
 (0)