pnp / modernization

All modernization tooling and guidance
http://aka.ms/sppnp-modernize
MIT License
157 stars 86 forks source link

[BUG] _'0x0D' is invalid within a JSON string. The string should be correctly escaped. #627

Open krisshelly opened 2 years ago

krisshelly commented 2 years ago

Problem Area

[X] Page Transformation: Error during the use of page transformation from PnP PowerShell

Expected or Desired Behavior

ConvertTo-PnPPage should modernize the web part pages having script editor web parts. It should convert classic OOB script editor web parts to configured react script editor web part.

PnP PowerShell Online Version Details: Name: SharePointPnPPowerShellOnline
Version: 3.29.2101.0

Observed Behavior

Getting the below error while trying to modernize the page with script editor web part:

_'0x0D' is invalid within a JSON string. The string should be correctly escaped. Path: $ | LineNumber: 0 | BytePositionInLine: 317. at System.Text.Json.ThrowHelper.ReThrowWithPath(ReadStack& readStack, JsonReaderException ex) at System.Text.Json.JsonSerializer.ReadCore(JsonSerializerOptions options, Utf8JsonReader& reader, ReadStack& readStack) at System.Text.Json.JsonSerializer.ReadCore(Type returnType, JsonSerializerOptions options, Utf8JsonReader& reader) at System.Text.Json.JsonSerializer.Deserialize(String json, Type returnType, JsonSerializerOptions options) at System.Text.Json.JsonSerializer.Deserialize[TValue](String json, JsonSerializerOptions options) at PnP.Core.Model.SharePoint.PageWebPart.setPropertiesJson(String value) at PnP.Framework.Modernization.Transform.ContentTransformator.Transform(List`1 webParts) at PnP.Framework.Modernization.Transform.PageTransformator.Transform(PageTransformationInformation pageTransformationInformation)

Page Transformation Settings

Property Setting
Engine version 1.9.1.0
Target Page Takes Source Page Name False
Target Page Prefix Migrated_
Source Page Prefix Previous_
Copy Page Metadata True
Set Author In Page Header False
Replace Home Page With Default Home Page False
Overwrite True
Target Page Name
Target Page Folder
Target Page Folder Overrides Default Folder False
Keep Page Specific Permissions False
Remove Empty Sections And Columns True
Handle Wiki Images And Videos True
Add Table List Image As Image Web Part False
Keep Page Creation Modification Information True
Publish Created Page True
Post As News False
Disable Page Comments True
Skip Url Rewrite False
Skip Default Url Rewrite False
Url Mapping File
Skip Hidden Web Parts False
Term Mapping File
Skip Term Store Mapping False
Skip User Mapping False
User Mapping File
L D A P Connection String
Skip Telemetry False

Transformation Operation Details

Note: It is similar to issue https://github.com/pnp/modernization/issues/606

It is working fine if I remove the newline character from the script. But for us it is a lot of pages and will not be feasible to manually remove the newline character from each script. Is there any alternative solution to fix this issues for all of the pages.

Steps to Reproduce

Install the react-script editor web part to the app catalog from the link https://github.com/pnp/sp-dev-fx-webparts/tree/main/samples/react-script-editor Create a web part page in a classic SharePoint site, add OOB script editor web part and add the below sample script in the code snippet of the script editor web part.

Sample Script: `

My First JavaScript

` Then use the below script to modernize the page with the switch -UseCommunityScriptEditor: ConvertTo-PnPPage -Identity $page.FieldValues["ID"] ` -Overwrite ` -DisablePageComments ` -AddTableListImageAsImageWebPart: $false ` -ClearCache ` -SkipItemLevelPermissionCopyToClientSidePage ` -TakeSourcePageName:$TakeSourcePageName ` -LogType File ` -LogFolder $LogOutputFolder ` -LogVerbose ` -LogSkipFlush ` -KeepPageCreationModificationInformation ` -UseCommunityScriptEditor ` -CopyPageMetadata `
spevilgenius commented 7 months ago

I am also seeing this and can't locate the offending web part to even know how to troubleshoot. Several pages have web parts that get transformed but at least one fails with this error.