Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/Database/DataSnap    [ Add a report in this area ]  
Report #:  103674   Status: Closed
Error in TJsonString.ToString function
Project:  Delphi Build #:  16.0.4429.46931
Version:    16.4 Submitted By:   Bjarne Rasmussen
Report Type:  Crash / Data loss / Total failure Date Reported:  2/24/2012 5:34:07 AM
Severity:    Critical / Show Stopper Last Updated: 9/5/2012 7:58:37 PM
Platform:    All versions Internal Tracking #:   27121
Resolution: Fixed (Resolution Comments) Resolved in Build: : 17.0.4625.53395
Duplicate of:  None
Voting and Rating
Overall Rating: No Ratings Yet
0.00 out of 5
Total Votes: None
The method will only take the character " into account. And it should also handle the \ character.

As a result when using the tostring mehod - one has to check for the \ oneself - and in that process skip the \" - since it has been added by the tostring method.

It can be that this is not the right place to do this - but then it shouldn't take care of the other escape char " ...
Steps to Reproduce:
Setup any testproject and include DBXJson.pas file.

Create a TJsonString and set it to 'This is a "test" string.'
Use the ToSting mehod - and you will get "This is a \"test\" string."

Change the string to 'This is \another\ test string'
and the result is "This is \another\ test string"

The correct result should be :
"This is \\another\\ test string"

Can be easily fixed in DBXJson.Pas line 1532 - or so.

function TJSONString.ToString: UnicodeString;
  if FStrBuffer <> nil then
    Exit('"' + AnsiReplaceStr(AnsiReplaceStr(FStrBuffer.ToString, '\', '\\'), '"', '\"') + '"');
//    Exit('"' + AnsiReplaceStr(FStrBuffer.ToString, '"', '\"') + '"');
  Result := NullString;

Tomohiro Takahashi at 2/24/2012 7:51:36 AM -
Is your issue same as QC#103661 ?

Bjarne Rasmussen at 2/24/2012 3:37:38 PM -
It would seem that it is exactly the same issue - only difference is that I provide a workaround.
Problem is that the workaround has to be done i DBXJson.Pas file - better solution would be to solve it via a helper function.

I did search for similar errors before posting - but was not able to find any. Generally I find it a problem searching for "errors" ...

Tomohiro Takahashi at 2/25/2012 6:09:20 PM -
I will open this report after maintenance of internal system.

Tomohiro Takahashi at 2/25/2012 6:27:25 PM -
In previous version of Delphi(Delphi XE), we get
- "This is a "test" string."
- "This is \another\ test string"
without escape...

Bjarne Rasmussen at 2/26/2012 4:56:41 AM -
Well at least the previous version (Delphi XE) is consistent in its conversion (read - not doing any at all) ... and not like XE2 converting half.

Tomohiro Takahashi at 4/17/2012 6:40:43 AM -
This report was opened with valid Internal Tracking Number.

Tomohiro Takahashi at 10/15/2013 10:36:21 PM -
This issue is not fixed yet.
Please see QC#119779.

Server Response from: ETNACODE01