Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix url encoding issue when writing href values to client_LocationBasedDefaults.html as part of SetDefaultColumnValuesImplementation() #11

Merged
merged 1 commit into from
Oct 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/lib/PnP.Framework.Test/Utilities/UrlUtilityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,16 @@ public void ReplaceInvalidUrlCharsReturnsStrippedString()
var invalidString = "a#%*\\:<>?/+|b";
Assert.AreEqual("a---------------------------------b", invalidString.ReplaceInvalidUrlChars("---"));
}

[TestMethod]
public void UrlPathEncodePerformsUrlEncodingButLeavesSlashesAlone()
{
var input = "/sites/site001/document library/folder abc";
var expected = "/sites/site001/document%20library/folder%20abc";

var actual = input.UrlPathEncode();

Assert.AreEqual(expected, actual);
}
}
}
2 changes: 1 addition & 1 deletion src/lib/PnP.Framework/Extensions/ListExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1645,7 +1645,7 @@ private static void SetDefaultColumnValuesImplementation(this List list, IEnumer
path = path.Equals("/") ? list.RootFolder.ServerRelativeUrl : UrlUtility.Combine(list.RootFolder.ServerRelativeUrl, path);
// Find all in the same path:
var defaultColumnValuesInSamePath = columnValues.Where(x => x.FolderRelativePath == defaultColumnValue.FolderRelativePath);
path = System.Web.HttpUtility.UrlEncode(path);
path = path.UrlPathEncode();

var xATag = new XElement("a", new XAttribute("href", path));

Expand Down
14 changes: 12 additions & 2 deletions src/lib/PnP.Framework/Utilities/UrlUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,26 @@ public static string StripInvalidUrlChars(this string content)
return ReplaceInvalidUrlChars(content, "");
}
/// <summary>
/// Replaces invalid charcters with other characters
/// Replaces invalid characters with other characters
/// </summary>
/// <param name="content">Url value</param>
/// <param name="replacer">string need to replace with invalid characters</param>
/// <returns>Returns replaced invalid charcters from URL</returns>
/// <returns>Returns replaced invalid characters from URL</returns>
public static string ReplaceInvalidUrlChars(this string content, string replacer)
{
return new Regex(INVALID_CHARS_REGEX).Replace(content, replacer);
}

/// <summary>
/// Encodes URL encoded in a way that SharePoint expected URLs to be encoded in client_LocationBasedDefaults.html
/// </summary>
/// <param name="content">Url value</param>
/// <returns>Returns URL encoded in a way that SharePoint expected URLs to be encoded in client_LocationBasedDefaults.html</returns>
public static string UrlPathEncode(this string content)
{
return System.Web.HttpUtility.UrlPathEncode(content);
}

/// <summary>
/// Tells URL is virtual directory or not
/// </summary>
Expand Down