This bug took a while to track down and appears in WiseJ 2.0.28.0. I have a settings class that I am trying to store via a cookie, and using JSON serialization/deserialization.
Writing the JSON string to a cookie the first time looks like this (Visual Studio watch):
"{""cboIssuesDepartmentSelectedIndex"":0,""txtIssuesText"":"""",""txtIssuesAutoCompleteText"":[""""],""txtStaffSearchText"":"""",""txtStaffSearchAutoCompleteText"":[""1"",""2"",""test"",""3"",""4""],""cboStaffDeptFilterSelectedIndex"":-1,""cboIssuesFilterSelectedIndex"":1,""cboIssuesStatusSelectedIndex"":0,""cboIssuesTypeSelectedIndex"":0,""splitContainer1SplitterDistance"":1410,""scListViewMapSplitContainerSplitterDistance"":631}"
After saving the cookie, you can see the JSON is stored in the browser like this, double quotes were escaped: (Chrome Cookie Viewer)
{\"cboIssuesDepartmentSelectedIndex\":0,\"txtIssuesText\":\"\",\"txtIssuesAutoCompleteText\":[\"\"],\"txtStaffSearchText\":\"\",\"txtStaffSearchAutoCompleteText\":[\"1\",\"2\",\"test\",\"3\",\"4\"],\"cboStaffDeptFilterSelectedIndex\":-1,\"cboIssuesFilterSelectedIndex\":1,\"cboIssuesStatusSelectedIndex\":0,\"cboIssuesTypeSelectedIndex\":0,\"splitContainer1SplitterDistance\":1410,\"scListViewMapSplitContainerSplitterDistance\":631}
If we load that cookie again in the same session, it un-escapes the quotes, and is read just the way it was saved: (Visual Studio watch)
"{""cboIssuesDepartmentSelectedIndex"":0,""txtIssuesText"":"""",""txtIssuesAutoCompleteText"":[""""],""txtStaffSearchText"":"""",""txtStaffSearchAutoCompleteText"":[""1"",""2"",""test"",""3"",""4""],""cboStaffDeptFilterSelectedIndex"":-1,""cboIssuesFilterSelectedIndex"":1,""cboIssuesStatusSelectedIndex"":0,""cboIssuesTypeSelectedIndex"":0,""splitContainer1SplitterDistance"":1410,""scListViewMapSplitContainerSplitterDistance"":631}"
So far so good. This read/write/read cycle can be done over and over again successfully.
However, after rebuilding/restarting the session, the cookie is read like this:
"{\""cboIssuesDepartmentSelectedIndex\"":0,\""txtIssuesText\"":\""\"",\""txtIssuesAutoCompleteText\"":[\""\""],\""txtStaffSearchText\"":\""\"",\""txtStaffSearchAutoCompleteText\"":[\""1\"",\""2\"",\""test\"",\""3\"",\""4\""],\""cboStaffDeptFilterSelectedIndex\"":-1,\""cboIssuesFilterSelectedIndex\"":1,\""cboIssuesStatusSelectedIndex\"":0,\""cboIssuesTypeSelectedIndex\"":0,\""splitContainer1SplitterDistance\"":1410,\""scListViewMapSplitContainerSplitterDistance\"":631}"
and throws a JSON deserialization error. Notice the first few characters are different.
Newtonsoft JSON.NET error message is Invalid Property identifier character: \. Path”, line 1, position 1.
A sample is provided. To reproduce:
Looks like a bug. Writing the cookie applies an additional escaping of the json string. You see it only on a new session because that’s the only time the cookies are reloaded from the browser. When you add the cookie it stays in the collection. It was probably added to solve (but it doesn’t) a general bug with ASP.NET cookies not being able to contain the semicolon as part of the string.
As a temporary workaround use this:
Public Function JavaScriptStringDecode(source As String) As String Return source.Replace("\'", "'").Replace("\""", """").Replace("\/", "/").Replace("\t", "\t").Replace("\n", "\n") End Function
Logged as #1924, will be fixed in the upcoming (overdue) update.
Please login first to submit.