pnp / pnpcore

The PnP Core SDK is a modern .NET SDK designed to work for Microsoft 365. It provides a unified object model for working with SharePoint Online and Teams which is agnostic to the underlying API's being called
https://aka.ms/pnp/coresdk/docs
MIT License
288 stars 188 forks source link

New line in Check-In Comments, failing to save #1432

Closed ranaictiu closed 3 months ago

ranaictiu commented 3 months ago

Category

Describe the bug

If you call File.CheckInAsync(comments,CheckinType) with comments having new line '\n', or '%0Abb', the check-in fails with bad request/Invalid URL. Found out that when I try checkin with new line in SharePoint interface, the request looks something like below (uses parameters a1, a2..): _api/web/GetFileByServerRelativePath(DecodedUrl=@a1)/CheckIn(comment=@a2,checkintype=@a3)?@a1=%27%2Fsites%2Fsitename%2FDocumentsLibraryName%2FDocumentName%2Edocx%27&@a2=%27firstline%0Asecondline%27&@a3=0

However the same request is constructed as below in PnpCore (without parameters) _api/Web/lists(guid'doc-list-id')/items(21)/file/checkin(comment='firstline%0Asecondline',checkintype=0)

Steps to reproduce

When use below comments (with newline or encoded) to checkin fails.

var comments = "aa%0Abb"; // or "aa\nbb"
await item.File.CheckinAsync(comments, CheckinType.MinorCheckIn);

However if I use the below - which passes comments as parameter, it works.

var comments = "aa%0Abb";
var url = $"http://SITEURL/_api/web/GetFileByServerRelativePath(DecodedUrl=@a1)/CheckIn(comment=@a2,checkintype=@a3)?@a1=%27DOCUMENT_URL%27&@a2=%27{comments}%27&@a3=0";
var httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, url);
await context.AuthenticationProvider.AuthenticateRequestAsync(new Uri("https://SITEURL"), httpRequestMessage);
var r = await context.RestClient.Client.SendAsync(httpRequestMessage,HttpCompletionOption.ResponseContentRead);

Expected behavior

Check-in should work with comments having new-line (encoded).

Environment details (development & target environment)

SharePoint Online

Thanks for your contribution! Sharing is caring.

jansenbe commented 3 months ago

Thanks for reporting this @ranaictiu and thanks for pointing out the fix. I've just fixed this in PnP Core SDK, this change will be part of the next nightly build. Hence I'm closing this issue now, if you still see issues then please re-open or create a new issue.