Altinn / Altinn/app-lib-dotnet

Prefill-dictionary does not allow string containing a single quote

Open
#928 0 comments 0 reactions 1 assignee Claimed by @adamhaeger View on GitHub
kind/bug
Dominant language
C#
Stars
8
Forks
27
Avg merge
1h 21m
Merged PRs (30d)
7

Description

### Description of the bug

Got an error when instansiating schema `dat/bemanning-aarligmelding` with HTTP POST simplified instansiation and this request body:

```json
{
"instanceOwner": {
"partyId": null,
"personNumber": null,
"organisationNumber": "924713992"
},
"dueBefore": "2025-01-01T00:00:00.0000000",
"visibleAfter": null,
"prefill": {
"Prefill.EraSourceEnvironment": "prod",
"Prefill.KanOppretteAarligMelding": "True",
"Prefill.ArkivSaksId": "1203228",
"Prefill.InnsendingSvarfrist": "2025-01-01T00:00:00.0000000",
"Prefill.YrkesskadeforsikringPolisenummer": "301738.1",
"Prefill.YrkesskadeforsikringNavn": "S'oderberg og Partners",
"Prefill.YrkesskadeforsikringGyldigTilDato": "2023-12-31T12:00:00.000+01:00"
}
}
```

Error:
```console
Newtonsoft.Json.JsonReaderException:
at Newtonsoft.Json.JsonTextReader.Read (Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed)
at Newtonsoft.Json.Linq.JToken.Parse (Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed)
at Altinn.App.Core.Implementation.PrefillSI.LoopThroughDictionaryAndAssignValuesToDataModel (Altinn.App.Core, Version=8.3.4.142, Culture=neutral, PublicKeyToken=null)
at Altinn.App.Core.Implementation.PrefillSI.PrefillDataModel (Altinn.App.Core, Version=8.3.4.142, Culture=neutral, PublicKeyToken=null)
at Altinn.App.Core.Implementation.PrefillSI+d__13.MoveNext (Altinn.App.Core, Version=8.3.4.142, Culture=neutral, PublicKeyToken=null)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Altinn.App.Core.Internal.Process.ProcessTasks.ProcessTaskInitializer+d__8.MoveNext (Altinn.App.Core, Version=8.3.4.142, Culture=neutral, PublicKeyToken=null)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Altinn.App.Core.Internal.Process.EventHandlers.ProcessTask.StartTaskEventHandler+d__4.MoveNext (Altinn.App.Core, Version=8.3.4.142, Culture=neutral, PublicKeyToken=null)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Altinn.App.Core.Internal.Process.ProcessEventHandlingDelegator+d__7.MoveNext (Altinn.App.Core, Version=8.3.4.142, Culture=neutral, PublicKeyToken=null)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Altinn.App.Core.Internal.Process.ProcessEngine+d__11.MoveNext (Altinn.App.Core, Version=8.3.4.142, Culture=neutral, PublicKeyToken=null)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult (System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Altinn.App.Api.Controllers.InstancesController+d__21.MoveNext (Altinn.App.Api, Version=8.3.4.142, Culture=neutral, PublicKeyToken=null)
```

It seems that the error originate from the following line: https://github.com/Altinn/app-lib-dotnet/blob/723992f221cc6dafea7d717c215416254bbf8f86/src/Altinn.App.Core/Implementation/PrefillSI.cs#L306

The problem is that a string value in the prefill-dict contains a single quote:

```json
"Prefill.YrkesskadeforsikringNavn": "S'oderberg og Partners"
```

### Steps To Reproduce

Instansiate a new schema with simplified instansiation, HTTP POST request against `https://dat.apps.altinn.no//instances/create` with a prefill-dict that contains a single quote in a text string:

```json
{
"instanceOwner": {
"partyId": null,
"personNumber": null,
"organisationNumber": ""
},
"dueBefore": null,
"visibleAfter": null,
"prefill": {
"Foobar": "String contain'ing a single quote"
}
}
```

### Additional Information

Altinn.App.Core version 8.3.4

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.