Skip to content

Commit

Permalink
Merge branch 'fix_UrlEncodingDecoding' of https://github.com/MondayCo…
Browse files Browse the repository at this point in the history
  • Loading branch information
jansenbe committed Oct 29, 2021
2 parents 8a61c5d + cf4a5c2 commit c545b65
Show file tree
Hide file tree
Showing 21 changed files with 60 additions and 58 deletions.
16 changes: 8 additions & 8 deletions src/lib/PnP.Framework/Extensions/BrandingExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,10 @@ public static void SetComposedLookByUrl(this Web web, string lookName, string pa
}

//URL decode retrieved URL's
paletteUrl = System.Net.WebUtility.UrlDecode(paletteUrl);
fontUrl = System.Net.WebUtility.UrlDecode(fontUrl);
backgroundUrl = System.Net.WebUtility.UrlDecode(backgroundUrl);
masterUrl = System.Net.WebUtility.UrlDecode(masterUrl);
paletteUrl = !string.IsNullOrWhiteSpace(paletteUrl)?Uri.UnescapeDataString(paletteUrl):default(string);
fontUrl = !string.IsNullOrWhiteSpace(fontUrl)?Uri.UnescapeDataString(fontUrl):default(string);
backgroundUrl = !string.IsNullOrWhiteSpace(backgroundUrl)?Uri.UnescapeDataString(backgroundUrl):default(string);
masterUrl = !string.IsNullOrWhiteSpace(masterUrl)?Uri.UnescapeDataString(masterUrl):default(string);

if (!string.IsNullOrEmpty(masterUrl))
{
Expand Down Expand Up @@ -910,19 +910,19 @@ public static ThemeEntity GetComposedLook(this Web web, string composedLookName)

if (themeItem["MasterPageUrl"] != null && themeItem["MasterPageUrl"].ToString().Length > 0)
{
masterPageUrl = System.Net.WebUtility.UrlDecode((themeItem["MasterPageUrl"] as FieldUrlValue).Url);
masterPageUrl = Uri.UnescapeDataString((themeItem["MasterPageUrl"] as FieldUrlValue).Url);
}
if (themeItem["ImageUrl"] != null && themeItem["ImageUrl"].ToString().Length > 0)
{
imageUrl = System.Net.WebUtility.UrlDecode((themeItem["ImageUrl"] as FieldUrlValue).Url);
imageUrl = Uri.UnescapeDataString((themeItem["ImageUrl"] as FieldUrlValue).Url);
}
if (themeItem["FontSchemeUrl"] != null && themeItem["FontSchemeUrl"].ToString().Length > 0)
{
fontUrl = System.Net.WebUtility.UrlDecode((themeItem["FontSchemeUrl"] as FieldUrlValue).Url);
fontUrl = Uri.UnescapeDataString((themeItem["FontSchemeUrl"] as FieldUrlValue).Url);
}
if (themeItem["ThemeUrl"] != null && themeItem["ThemeUrl"].ToString().Length > 0)
{
themeUrl = System.Net.WebUtility.UrlDecode((themeItem["ThemeUrl"] as FieldUrlValue).Url);
themeUrl = Uri.UnescapeDataString((themeItem["ThemeUrl"] as FieldUrlValue).Url);
}
if (themeItem["Name"] != null && themeItem["Name"].ToString().Length > 0)
{
Expand Down
5 changes: 3 additions & 2 deletions src/lib/PnP.Framework/Extensions/FileFolderExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using PnP.Framework;
using PnP.Framework.Diagnostics;
using PnP.Framework.Enums;
using PnP.Framework.Provisioning.ObjectHandlers.Utilities;
using PnP.Framework.Utilities;
using PnP.Framework.Utilities.Async;
using System;
Expand Down Expand Up @@ -869,8 +870,8 @@ private static async Task<Folder> EnsureFolderPathImplementation(this Web web, s
Folder nextFolder = null;
foreach (Folder existingFolder in folderCollection)
{
//System.Net.WebUtility.UrlDecode removes + from folderName which leads to invalid compare if folderName was not UrlEncoded
if (string.Equals(existingFolder.Name, System.Net.WebUtility.UrlDecode(folderName), StringComparison.InvariantCultureIgnoreCase) || string.Equals(existingFolder.Name, folderName, StringComparison.InvariantCultureIgnoreCase))
//WebUtility.UrlDecode removes + from folderName which leads to invalid compare if folderName was not UrlEncoded --> replaced with Uri.UnescapeDatastring
if (string.Equals(existingFolder.Name, Uri.UnescapeDataString(folderName), StringComparison.InvariantCultureIgnoreCase) || string.Equals(existingFolder.Name, folderName, StringComparison.InvariantCultureIgnoreCase))
{
nextFolder = existingFolder;
break;
Expand Down
6 changes: 3 additions & 3 deletions src/lib/PnP.Framework/Extensions/ListExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1831,7 +1831,7 @@ public static void SetDefaultColumnValues(this List list, IEnumerable<IDefaultCo
foreach (var value in values)
{
var href = value.Attribute("href").Value;
href = System.Web.HttpUtility.UrlDecode(href);
href = Uri.UnescapeDataString(href);
href = href.Replace(list.RootFolder.ServerRelativeUrl, "/").Replace("//", "/");
var defaultValues = from d in value.Descendants("DefaultValue") select d;
foreach (var defaultValue in defaultValues)
Expand Down Expand Up @@ -2052,7 +2052,7 @@ public static void ClearDefaultColumnValues(this List list, IEnumerable<IDefault
foreach (var value in values)
{
var href = value.Attribute("href").Value;
href = System.Web.HttpUtility.UrlDecode(href);
href = Uri.UnescapeDataString(href);

href = href.Replace(list.RootFolder.ServerRelativeUrl, "/").Replace("//", "/");
var defaultValues = from d in value.Descendants("DefaultValue") select d;
Expand Down Expand Up @@ -2184,7 +2184,7 @@ public static List<Dictionary<string, string>> GetDefaultColumnValues(this List
foreach (var value in values)
{
var href = value.Attribute("href").Value;
href = System.Web.HttpUtility.UrlDecode(href);
href = Uri.UnescapeDataString(href);
href = href.Replace(list.RootFolder.ServerRelativeUrl, "/").Replace("//", "/");

var defaultValues = from d in value.Descendants("DefaultValue") select d;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ internal void PersistFile(Web web, ProvisioningTemplateCreationInformation creat
}

String container = folderPath.Trim('/').Replace("%20", " ").Replace("/", "\\");
String persistenceFileName = (decodeFileName ? HttpUtility.UrlDecode(fileName) : fileName).Replace("%20", " ");
String persistenceFileName = (decodeFileName ? Uri.UnescapeDataString(fileName) : fileName).Replace("%20", " ");

if (fileConnector.Parameters.ContainsKey(FileConnectorBase.CONTAINER))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -806,8 +806,8 @@ private IEnumerable<ContentType> GetEntities(Web web, PnPMonitoredScope scope, P
// If we got here it's a file, let's grab the file's path and name
var baseUri = new Uri(web.Url);
var fullUri = new Uri(baseUri, spFile.ServerRelativePath.DecodedUrl);
var folderPath = System.Web.HttpUtility.UrlDecode(fullUri.Segments.Take(fullUri.Segments.Length- 1).ToArray().Aggregate((i, x) => i + x).TrimEnd('/'));
var fileName = System.Web.HttpUtility.UrlDecode(fullUri.Segments[fullUri.Segments.Length - 1]);
var folderPath = Uri.UnescapeDataString(fullUri.Segments.Take(fullUri.Segments.Length- 1).ToArray().Aggregate((i, x) => i + x).TrimEnd('/'));
var fileName = Uri.UnescapeDataString(fullUri.Segments[fullUri.Segments.Length - 1]);

var templateFolderPath = folderPath.Substring(web.ServerRelativeUrl.Length).TrimStart("/".ToCharArray());

Expand Down Expand Up @@ -925,8 +925,8 @@ private IEnumerable<ContentType> GetEntities(Web web, PnPMonitoredScope scope, P
// If we got here it's a file, let's grab the file's path and name
var baseUri = new Uri(web.Url);
var fullUri = new Uri(baseUri, spFile.ServerRelativePath.DecodedUrl);
var folderPath = System.Web.HttpUtility.UrlDecode(fullUri.Segments.Take(fullUri.Segments.Length - 1).ToArray().Aggregate((i, x) => i + x).TrimEnd('/'));
var fileName = System.Web.HttpUtility.UrlDecode(fullUri.Segments[fullUri.Segments.Length- 1]);
var folderPath = Uri.UnescapeDataString(fullUri.Segments.Take(fullUri.Segments.Length - 1).ToArray().Aggregate((i, x) => i + x).TrimEnd('/'));
var fileName = Uri.UnescapeDataString(fullUri.Segments[fullUri.Segments.Length- 1]);

var templateFolderPath = folderPath.Substring(web.ServerRelativeUrl.Length).TrimStart("/".ToCharArray());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ private static File UploadFile(Microsoft.SharePoint.Client.Folder folder, Stream
if (ex.ServerErrorCode != -2130575306) //Error code: -2130575306 = The file is already checked out.
{
//The file name might contain encoded characters that prevent upload. Decode it and try again.
fileName = WebUtility.UrlDecode(fileName);
fileName = Uri.UnescapeDataString(fileName);
try
{
targetFile = folder.UploadFile(fileName, stream, overwrite);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ protected string Tokenize(string url, string webUrl, Web web = null)
Uri uri;
if (Uri.TryCreate(webUrl, UriKind.Absolute, out uri))
{
string webUrlPathAndQuery = System.Web.HttpUtility.UrlDecode(uri.PathAndQuery);
string webUrlPathAndQuery = Uri.UnescapeDataString(uri.PathAndQuery);
// Don't do additional replacement when masterpagecatalog and themecatalog (see #675)
if (url.IndexOf(webUrlPathAndQuery, StringComparison.InvariantCultureIgnoreCase) > -1 && (url.IndexOf("{masterpagecatalog}") == -1) && (url.IndexOf("{themecatalog}") == -1))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,8 @@ private static void ProcessFormsFolder(Web web, List spList, ListInstance listIn
if (!string.IsNullOrWhiteSpace(url) && !string.IsNullOrWhiteSpace(contentTypeId))
{
var fullUri = new Uri(baseUri, url.Replace("{site}", baseUri.AbsolutePath.TrimEnd('/')));
var folderPath = HttpUtility.UrlDecode(fullUri.Segments.Take(fullUri.Segments.Length - 1).ToArray().Aggregate((i, x) => i + x).TrimEnd('/'));
var fileName = HttpUtility.UrlDecode(fullUri.Segments[fullUri.Segments.Length - 1]);
var folderPath = Uri.UnescapeDataString(fullUri.Segments.Take(fullUri.Segments.Length - 1).ToArray().Aggregate((i, x) => i + x).TrimEnd('/'));
var fileName = Uri.UnescapeDataString(fullUri.Segments[fullUri.Segments.Length - 1]);

var templateFolderPath = folderPath.Substring(web.ServerRelativeUrl.Length).TrimStart('/');

Expand Down Expand Up @@ -511,8 +511,8 @@ private void ProcessDocumentRow(Web web, List siteList, Uri baseUri, ListItem li

// If we got here it's a file, let's grab the file's path and name
var fullUri = new Uri(baseUri, myFile.ServerRelativePath.DecodedUrl);
var folderPath = System.Web.HttpUtility.UrlDecode(fullUri.Segments.Take(fullUri.Segments.Length - 1).ToArray().Aggregate((i, x) => i + x).TrimEnd('/'));
var fileName = System.Web.HttpUtility.UrlDecode(fullUri.Segments[fullUri.Segments.Length - 1]);
var folderPath = Uri.UnescapeDataString(fullUri.Segments.Take(fullUri.Segments.Length - 1).ToArray().Aggregate((i, x) => i + x).TrimEnd('/'));
var fileName = Uri.UnescapeDataString(Path.GetFileName(fullUri.AbsoluteUri));

var templateFolderPath = folderPath.Substring(web.ServerRelativeUrl.Length).TrimStart("/".ToCharArray());

Expand Down Expand Up @@ -909,7 +909,7 @@ private Model.DataRow ProcessDataRow(Web web, List siteList, ListItem item, List
foreach (var attachmentFile in item.AttachmentFiles)
{
var fullUri = new Uri(baseUri, attachmentFile.ServerRelativePath.DecodedUrl);
var folderPath = HttpUtility.UrlDecode(fullUri.Segments.Take(fullUri.Segments.Length - 1).ToArray().Aggregate((i, x) => i + x).TrimEnd('/'));
var folderPath = Uri.UnescapeDataString(fullUri.Segments.Take(fullUri.Segments.Length - 1).ToArray().Aggregate((i, x) => i + x).TrimEnd('/'));
var targetFolder = $"ListData/SITE_{web.Id.ToString("N")}/LIST_{siteList.Id.ToString("N")}/Attachments/{item.Id}";
dataRow.Attachments.Add(new Model.SharePoint.InformationArchitecture.DataRowAttachment()
{
Expand All @@ -929,7 +929,7 @@ private void PersistFile(Web web, ProvisioningTemplateCreationInformation creati
{
if (creationInfo.FileConnector != null)
{
var targetContainer = HttpUtility.UrlDecode(targetFolder).Trim('/').Replace("/", "\\");
var targetContainer = Uri.UnescapeDataString(targetFolder).Trim('/').Replace("/", "\\");

using (Stream s = GetAttachmentStream((ClientContext)web.Context, fileServerRelativeUrl))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,12 @@ private void ExtractMasterPagesAndPageLayouts(Web web, ProvisioningTemplate temp
file.EnsureProperty(f => f.Level);

var containerPath = folderPath.StartsWith(web.ServerRelativeUrl) && web.ServerRelativeUrl != "/" ? folderPath.Substring(web.ServerRelativeUrl.Length) : folderPath;
var container = HttpUtility.UrlDecode(containerPath).Trim('/').Replace("/", "\\");
var container = Uri.UnescapeDataString(containerPath).Trim('/').Replace("/", "\\");

var publishingFile = new Model.File()
{
Folder = Tokenize(folderPath, web.Url),
Src = !string.IsNullOrEmpty(container) ? $"{container}\\{HttpUtility.UrlDecode(fileName)}" : HttpUtility.UrlDecode(fileName),
Src = !string.IsNullOrEmpty(container) ? $"{container}\\{Uri.UnescapeDataString(fileName)}" : Uri.UnescapeDataString(fileName),
Overwrite = true,
Level = (Model.FileLevel)Enum.Parse(typeof(Model.FileLevel), file.Level.ToString())
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,13 @@ private bool PersistFile(Web web, ProvisioningTemplateCreationInformation creati
file.EnsureProperty(f => f.ServerRelativePath);
var baseUri = new Uri(web.Url);
var fullUri = new Uri(baseUri, file.ServerRelativePath.DecodedUrl);
var folderPath = HttpUtility.UrlDecode(fullUri.Segments.Take(fullUri.Segments.Length - 1).ToArray().Aggregate((i, x) => i + x).TrimEnd('/'));
var folderPath = Uri.UnescapeDataString(fullUri.Segments.Take(fullUri.Segments.Length - 1).ToArray().Aggregate((i, x) => i + x).TrimEnd('/'));

// Configure the filename to use
fileName = HttpUtility.UrlDecode(fullUri.Segments[fullUri.Segments.Length - 1]);
fileName = Uri.UnescapeDataString(fullUri.Segments[fullUri.Segments.Length - 1]);

// Build up a site relative container URL...might end up empty as well
String container = HttpUtility.UrlDecode(folderPath.Replace(web.ServerRelativeUrl, "")).Trim('/').Replace("/", "\\");
String container = Uri.UnescapeDataString(folderPath.Replace(web.ServerRelativeUrl, "")).Trim('/').Replace("/", "\\");

using (Stream memStream = new MemoryStream())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,8 @@ private Tuple<bool, string, string> LoadAndAddSyntexFile(Web web, Microsoft.Shar
syntexFile.EnsureProperty(p => p.ServerRelativePath);

var fullUri = new Uri(baseUri, syntexFile.ServerRelativePath.DecodedUrl);
var folderPath = HttpUtility.UrlDecode(fullUri.Segments.Take(fullUri.Segments.Length - 1).ToArray().Aggregate((i, x) => i + x).TrimEnd('/'));
var fileName = HttpUtility.UrlDecode(fullUri.Segments[fullUri.Segments.Length - 1]);
var folderPath = Uri.UnescapeDataString(fullUri.Segments.Take(fullUri.Segments.Length - 1).ToArray().Aggregate((i, x) => i + x).TrimEnd('/'));
var fileName = Uri.UnescapeDataString(fullUri.Segments[fullUri.Segments.Length - 1]);

var templateFolderPath = folderPath.Substring(web.ServerRelativeUrl.Length).TrimStart("/".ToCharArray());

Expand Down Expand Up @@ -315,9 +315,9 @@ private void PersistFile(Web web, ProvisioningTemplateCreationInformation creati
}
}

folderPath = HttpUtility.UrlDecode(folderPath);
string container = HttpUtility.UrlDecode(folderPath).Trim('/').Replace("/", "\\");
string persistenceFileName = HttpUtility.UrlDecode(fileName);
folderPath = Uri.UnescapeDataString(folderPath);
string container = Uri.UnescapeDataString(folderPath).Trim('/').Replace("/", "\\");
string persistenceFileName = Uri.UnescapeDataString(fileName);

if (fileConnector.Parameters.ContainsKey(FileConnectorBase.CONTAINER))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -991,7 +991,7 @@ public static bool SetTeamTabs(PnPMonitoredScope scope, TokenParser parser, Team
// Avoid ActivityLimitReached
System.Threading.Thread.Sleep(TimeSpan.FromSeconds(5));

var existingTab = existingTabs.FirstOrDefault(x => x["displayName"] != null && HttpUtility.UrlDecode(x["displayName"].ToString()) == tab.DisplayName && x["teamsApp"]?["id"]?.ToString() == tab.TeamsAppId);
var existingTab = existingTabs.FirstOrDefault(x => x["displayName"] != null && Uri.UnescapeDataString(x["displayName"].ToString()) == tab.DisplayName && x["teamsApp"]?["id"]?.ToString() == tab.TeamsAppId);

var tabId = existingTab == null ? CreateTeamTab(scope, tab, parser, teamId, channelId, accessToken) : UpdateTeamTab(tab, parser, teamId, channelId, existingTab["id"].ToString(), accessToken);

Expand Down
Loading

0 comments on commit c545b65

Please sign in to comment.