From 9bcf1ea8473fbeeee87d8e07011e30ae22cf1dc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Angel=20Garc=C3=ADa=20Mart=C3=ADnez?= Date: Tue, 24 Oct 2023 11:38:20 +0200 Subject: [PATCH] Escape apostrophe in alias before calling DirectorySession/Group method Escape apostrophe in alias before calling DirectorySession/Group method. Escape single quotes, for instance, when the alias is something like "What's new", it should be escaped to "What''s new". --- src/lib/PnP.Framework/Sites/SiteCollection.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/lib/PnP.Framework/Sites/SiteCollection.cs b/src/lib/PnP.Framework/Sites/SiteCollection.cs index 31a4bd0e2..9b594f9f9 100644 --- a/src/lib/PnP.Framework/Sites/SiteCollection.cs +++ b/src/lib/PnP.Framework/Sites/SiteCollection.cs @@ -1091,6 +1091,9 @@ public static async Task AliasExistsAsync(ClientContext context, string al var httpClient = PnPHttpClient.Instance.GetHttpClient(context); #pragma warning restore CA2000 // Dispose objects before losing scope + // Escape single quotes, for instance, when the alias is something like "What's new", it should be escaped to "What''s new" + alias = alias.Replace("'", "''"); + string requestUrl = string.Format("{0}/_api/SP.Directory.DirectorySession/Group(alias='{1}')", context.Web.Url, alias); using (HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, requestUrl)) { @@ -1152,6 +1155,9 @@ public static async Task> GetGroupInfoAsync(ClientCon var httpClient = PnPHttpClient.Instance.GetHttpClient(context); #pragma warning restore CA2000 // Dispose objects before losing scope + // Escape single quotes, for instance, when the alias is something like "What's new", it should be escaped to "What''s new" + alias = alias.Replace("'", "''"); + string requestUrl = string.Format("{0}/_api/SP.Directory.DirectorySession/Group(alias='{1}')", context.Web.Url, alias); using (HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, requestUrl)) {