Skip to content

Commit 5c6a7e4

Browse files
authored
Merge pull request #5459 from till-llit/fix/user-profile-apostrophe-odata
Fix apostrophes in user profile REST calls
2 parents c67f257 + 9d8f6e9 commit 5c6a7e4

5 files changed

Lines changed: 8 additions & 5 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
1313
### Changed
1414

1515
### Fixed
16+
- Using UPNs with an apostrophe in it not working with `Remove-PnPUserProfile`, `Export-PnPUserProfile`, `Export-PnPUserInfo`, and `Remove-PnPUserInfo`. The apostrophe is now escaped in the API request. [#5459](https://github.com/pnp/powershell/pull/5459)
1617

1718
## [3.4.1]
1819

@@ -24,6 +25,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
2425
### Contributors
2526

2627
- Gautam Sheth [gautamdsheth]
28+
- [till-llit]
2729

2830
## [3.4.0]
2931

‎src/Commands/Principals/ExportUserInfo.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ protected override void ExecuteCmdlet()
3232
var site = Tenant.GetSiteByUrl(siteUrl);
3333
AdminContext.Load(site);
3434
AdminContext.ExecuteQueryRetry();
35-
var normalizedUserName = UrlUtilities.UrlEncode($"i:0#.f|membership|{LoginName}");
35+
var normalizedUserName = UrlUtilities.UrlEncode($"i:0#.f|membership|{LoginName}".Replace("'", "''"));
3636
var results = RestHelper.Get<RestResultCollection<ExportEntity>>(Connection.HttpClient, $"{hostUrl}/_api/sp.userprofiles.peoplemanager/GetSPUserInformation(accountName=@a,siteId=@b)?@a='{normalizedUserName}'&@b='{site.Id}'", AdminContext, false);
3737
var record = new PSObject();
3838
foreach (var item in results.Items)

‎src/Commands/Principals/RemoveUserInfo.cs‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,16 @@ protected override void ExecuteCmdlet()
3535
var site = Tenant.GetSiteByUrl(siteUrl);
3636
AdminContext.Load(site);
3737
AdminContext.ExecuteQueryRetry();
38-
var normalizedUserName = UrlUtilities.UrlEncode($"i:0#.f|membership|{LoginName}");
38+
var normalizedUserName = UrlUtilities.UrlEncode($"i:0#.f|membership|{LoginName}".Replace("'", "''"));
3939
RestResultCollection<ExportEntity> results = null;
4040
if (!ParameterSpecified(nameof(RedactName)))
4141
{
4242
results = RestHelper.Post<RestResultCollection<ExportEntity>>(HttpClient, $"{hostUrl}/_api/sp.userprofiles.peoplemanager/RemoveSPUserInformation(accountName=@a,siteId=@b)?@a='{normalizedUserName}'&@b='{site.Id}'", this.AccessToken, false);
4343
}
4444
else
4545
{
46-
results = RestHelper.Post<RestResultCollection<ExportEntity>>(HttpClient, $"{hostUrl}/_api/sp.userprofiles.peoplemanager/RemoveSPUserInformation(accountName=@a,siteId=@b,redactName=@c)?@a='{normalizedUserName}'&@b='{site.Id}'&@c='{RedactName}'", this.AccessToken, false);
46+
var redactName = UrlUtilities.UrlEncode(RedactName.Replace("'", "''"));
47+
results = RestHelper.Post<RestResultCollection<ExportEntity>>(HttpClient, $"{hostUrl}/_api/sp.userprofiles.peoplemanager/RemoveSPUserInformation(accountName=@a,siteId=@b,redactName=@c)?@a='{normalizedUserName}'&@b='{site.Id}'&@c='{redactName}'", this.AccessToken, false);
4748
}
4849
var record = new PSObject();
4950
foreach (var item in results.Items)

‎src/Commands/UserProfiles/ExportUserProfile.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ protected override void ExecuteCmdlet()
2020
{
2121
hostUrl = hostUrl.Substring(0, hostUrl.Length - 1);
2222
}
23-
var normalizedUserName = UrlUtilities.UrlEncode($"i:0#.f|membership|{LoginName}");
23+
var normalizedUserName = UrlUtilities.UrlEncode($"i:0#.f|membership|{LoginName}".Replace("'", "''"));
2424
var results = RestHelper.Get<RestResultCollection<ExportEntity>>(Connection.HttpClient, $"{hostUrl}/_api/sp.userprofiles.peoplemanager/GetUserProfileProperties(accountName=@a)?@a='{normalizedUserName}'", AdminContext, false);
2525
var record = new PSObject();
2626
foreach (var item in results.Items)

‎src/Commands/UserProfiles/RemoveUserProfile.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ protected override void ExecuteCmdlet()
2222
{
2323
hostUrl = hostUrl.Substring(0, hostUrl.Length - 1);
2424
}
25-
var normalizedUserName = UrlUtilities.UrlEncode($"i:0#.f|membership|{LoginName}");
25+
var normalizedUserName = UrlUtilities.UrlEncode($"i:0#.f|membership|{LoginName}".Replace("'", "''"));
2626

2727
if (!ParameterSpecified(nameof(UserId)))
2828
{

0 commit comments

Comments
 (0)