Skip to content

Commit

Permalink
Ensure GetFolderByServerRelativeUrl and `GetFileByServerRelativeUr …
Browse files Browse the repository at this point in the history
…l` can handle \ as path separator #1412
  • Loading branch information
jansenbe committed Mar 13, 2024
1 parent abc1815 commit e500bba
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Verify TermId is a valid GUID before assigning it #1414 [jansenbe - Bert Jansen]
- Loading site pages is more robust when a custom web part on the page is erroring #1410 [jansenbe - Bert Jansen]
- `IContentType.SchemaXml` is not settable in SharePoint so removing the set option for it #1418 [jansenbe - Bert Jansen]
- Ensure `GetFolderByServerRelativeUrl` and `GetFileByServerRelativeUr l` can handle \ as path separator #1412 [jansenbe - Bert Jansen]

## [1.12.0]

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"IsSuccessStatusCode":true,"StatusCode":200,"Headers":{"SPRequestGuid":"57b114a1-f065-8000-4eb4-cbe709f88b18","SPClientServiceRequestDuration":"9","X-SharePointHealthScore":"3","X-SP-SERVERSTATE":"ReadOnly=0"},"Response":"{\u0022RegionalSettings\u0022:{\u0022TimeZone\u0022:{\u0022Description\u0022:\u0022(UTC-08:00) Pacific Time (US and Canada)\u0022,\u0022Id\u0022:13,\u0022Information\u0022:{\u0022Bias\u0022:480,\u0022DaylightBias\u0022:-60,\u0022StandardBias\u0022:0}},\u0022AdjustHijriDays\u0022:0,\u0022AlternateCalendarType\u0022:0,\u0022AM\u0022:\u0022AM\u0022,\u0022CalendarType\u0022:1,\u0022Collation\u0022:25,\u0022CollationLCID\u0022:2070,\u0022DateFormat\u0022:0,\u0022DateSeparator\u0022:\u0022/\u0022,\u0022DecimalSeparator\u0022:\u0022.\u0022,\u0022DigitGrouping\u0022:\u00223;0\u0022,\u0022FirstDayOfWeek\u0022:0,\u0022FirstWeekOfYear\u0022:0,\u0022IsEastAsia\u0022:false,\u0022IsRightToLeft\u0022:false,\u0022IsUIRightToLeft\u0022:false,\u0022ListSeparator\u0022:\u0022,\u0022,\u0022LocaleId\u0022:1033,\u0022NegativeSign\u0022:\u0022-\u0022,\u0022NegNumberMode\u0022:1,\u0022PM\u0022:\u0022PM\u0022,\u0022PositiveSign\u0022:\u0022\u0022,\u0022ShowWeeks\u0022:false,\u0022ThousandSeparator\u0022:\u0022,\u0022,\u0022Time24\u0022:false,\u0022TimeMarkerPosition\u0022:0,\u0022TimeSeparator\u0022:\u0022:\u0022,\u0022WorkDayEndHour\u0022:1020,\u0022WorkDays\u0022:62,\u0022WorkDayStartHour\u0022:480},\u0022Id\u0022:\u00222c99a486-d6c9-4a4b-8d6f-a9faa364c92c\u0022,\u0022Url\u0022:\u0022https://bertonline.sharepoint.com/sites/prov-2\u0022}"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"IsSuccessStatusCode":true,"StatusCode":200,"Headers":{"SPRequestGuid":"57b114a1-3076-8000-5b5f-612923ffc3ff","SPClientServiceRequestDuration":"10","X-SharePointHealthScore":"3","X-SP-SERVERSTATE":"ReadOnly=0"},"Response":"{\u0022GroupId\u0022:\u0022d40d729b-df60-4b57-ac8f-102595090e0a\u0022,\u0022Id\u0022:\u0022f92f9e40-1110-43ef-aa0e-0822e13fb7ba\u0022}"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"IsSuccessStatusCode":true,"StatusCode":200,"Headers":{"SPRequestGuid":"5eb114a1-2010-8000-5b5f-63c66937eae7","SPClientServiceRequestDuration":"13","X-SharePointHealthScore":"2","X-SP-SERVERSTATE":"ReadOnly=0"},"Response":"{\u0022Exists\u0022:true,\u0022ExistsAllowThrowForPolicyFailures\u0022:true,\u0022IsWOPIEnabled\u0022:false,\u0022ItemCount\u0022:4,\u0022Name\u0022:\u0022Shared Documents\u0022,\u0022ProgID\u0022:null,\u0022ServerRelativeUrl\u0022:\u0022/sites/prov-2/Shared Documents\u0022,\u0022TimeCreated\u0022:\u00222021-09-11T23:42:33Z\u0022,\u0022TimeLastModified\u0022:\u00222024-02-23T10:48:33Z\u0022,\u0022UniqueId\u0022:\u0022ee07fd66-8537-446f-a7d8-9fd90393188f\u0022,\u0022WelcomePage\u0022:\u0022\u0022}"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"IsSuccessStatusCode":true,"StatusCode":200,"Headers":{"SPRequestGuid":"60b114a1-50fa-8000-5b5f-6a0148c8bbb7","SPClientServiceRequestDuration":"15","X-SharePointHealthScore":"3","X-SP-SERVERSTATE":"ReadOnly=0"},"Response":"{\u0022Exists\u0022:true,\u0022ExistsAllowThrowForPolicyFailures\u0022:true,\u0022IsWOPIEnabled\u0022:false,\u0022ItemCount\u0022:4,\u0022Name\u0022:\u0022Shared Documents\u0022,\u0022ProgID\u0022:null,\u0022ServerRelativeUrl\u0022:\u0022/sites/prov-2/Shared Documents\u0022,\u0022TimeCreated\u0022:\u00222021-09-11T23:42:33Z\u0022,\u0022TimeLastModified\u0022:\u00222024-02-23T10:48:33Z\u0022,\u0022UniqueId\u0022:\u0022ee07fd66-8537-446f-a7d8-9fd90393188f\u0022,\u0022WelcomePage\u0022:\u0022\u0022}"}
16 changes: 16 additions & 0 deletions src/sdk/PnP.Core.Test/SharePoint/WebTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1404,6 +1404,22 @@ public async Task GetByServerRelativeSpecialChars()
}
}

[TestMethod]
public async Task GetByServerRelativeSeparatorEncoding()
{
//TestCommon.Instance.Mocking = false;
using (var context = await TestCommon.Instance.GetContextAsync(TestCommon.TestSite))
{
string sharedDocumentsFolderUrl = $"{context.Uri.PathAndQuery}/Shared Documents";
IFolder sharedDocumentsFolder = await context.Web.GetFolderByServerRelativeUrlAsync(sharedDocumentsFolderUrl);
Assert.IsNotNull(sharedDocumentsFolder);

sharedDocumentsFolderUrl = $"{context.Uri.PathAndQuery.Replace("/", "\\")}\\Shared Documents";
sharedDocumentsFolder = await context.Web.GetFolderByServerRelativeUrlAsync(sharedDocumentsFolderUrl);
Assert.IsNotNull(sharedDocumentsFolder);
}
}

[TestMethod]
public async Task GetWebChangesAsyncTest()
{
Expand Down
6 changes: 4 additions & 2 deletions src/sdk/PnP.Core/Model/SharePoint/Core/Internal/Web.cs
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,8 @@ private static ApiCall BuildGetFolderByRelativeUrlApiCall(string serverRelativeU
{
// NOTE WebUtility encode spaces to "+" instead of %20
// Replace %20 by space as otherwise %20 gets encoded as %2520 which will break the API request
string encodedServerRelativeUrl = WebUtility.UrlEncode(serverRelativeUrl.Replace("'", "''").Replace("%20", " ")).Replace("+", "%20");
// When using the "parameter" model (@u) the server relative URL has to be specified using /, using \ only works in the non parameterized version (#1412)
string encodedServerRelativeUrl = WebUtility.UrlEncode(serverRelativeUrl.Replace("'", "''").Replace("%20", " ").Replace("\\", "/")).Replace("+", "%20");
var apiCall = new ApiCall($"_api/Web/getFolderByServerRelativePath(decodedUrl=@u)?@u='{encodedServerRelativeUrl}'", ApiType.SPORest);
return apiCall;
}
Expand Down Expand Up @@ -584,7 +585,8 @@ private static ApiCall BuildGetFileByRelativeUrlApiCall(string serverRelativeUrl
{
// NOTE WebUtility encode spaces to "+" instead of %20
// Replace %20 by space as otherwise %20 gets encoded as %2520 which will break the API request
string encodedServerRelativeUrl = WebUtility.UrlEncode(serverRelativeUrl.Replace("'", "''").Replace("%20", " ")).Replace("+", "%20");
// When using the "parameter" model (@u) the server relative URL has to be specified using /, using \ only works in the non parameterized version (#1412)
string encodedServerRelativeUrl = WebUtility.UrlEncode(serverRelativeUrl.Replace("'", "''").Replace("%20", " ").Replace("\\", "/")).Replace("+", "%20");
var apiCall = new ApiCall($"_api/Web/getFileByServerRelativePath(decodedUrl=@u)?@u='{encodedServerRelativeUrl}'", ApiType.SPORest);
return apiCall;
}
Expand Down

0 comments on commit e500bba

Please sign in to comment.