View Issue Details

IDProjectCategoryView StatusLast Update
0038622FPCPackagespublic2021-03-14 22:55
ReporterBart Broersma Assigned ToMichael Van Canneyt  
PrioritynormalSeverityminorReproducibilityhave not tried
Status closedResolutionfixed 
Platformi386OSWindows 
Product Version3.3.1 
Fixed in Version3.3.1 
Summary0038622: JSONStringToString error when input contains consecutive \uxxxx blocks
DescriptionThe function JSONStringToString gives wrong result when the input contains consecutive block of the "\uxxxx" form.
Steps To Reproduce{$mode objfpc}
{$h+}
uses
  fpjson;

var
    S1, S2: TJSONStringType;
begin
  repeat
    write('S: ');readln(S2);
    S1 := JSONStringToString(S2);
    writeln(S1);
  until S2='';
end.

C:\Users\Bart\LazarusProjecten\ConsoleProjecten>fpc test.pas
Free Pascal Compiler version 3.3.1 [2021/03/14] for i386
Copyright (c) 1993-2021 by Florian Klaempfl and others
Target OS: Win32 for i386
Compiling test.pas
Linking test.exe
14 lines compiled, 0.2 sec, 246304 bytes code, 10228 bytes data

C:\Users\Bart\LazarusProjecten\ConsoleProjecten>test
S: \u0041\u0042
AAB
S: \u0041\u0042\u0043
AABC
S: \u0041\u0042\u0043\u0044
AABCCD
Additional InformationOf every block with 2 consecutive \uxxxx codes, the first one is repeated.
TagsNo tags attached.
Fixed in Revision48962
FPCOldBugId
FPCTarget4.0.0
Attached Files

Relationships

related to 0038618 resolvedMichael Van Canneyt Not processing "\u" characters in JSON String correctly. 

Activities

Bart Broersma

2021-03-14 15:10

reporter   ~0129653

Possible patch attached.
Also updates the test unit for jsondata.
jsonstringtostring.diff (1,114 bytes)   
Index: packages/fcl-json/src/fpjson.pp
===================================================================
--- packages/fcl-json/src/fpjson.pp	(revision 48960)
+++ packages/fcl-json/src/fpjson.pp	(working copy)
@@ -1014,6 +1014,7 @@
                 if (U1<>0) then
                   begin
                   App:={$IFDEF FPC_HAS_CPSTRING}UTF8Encode({$ENDIF}WideChar(U1)+WideChar(U2){$IFDEF FPC_HAS_CPSTRING}){$ENDIF};
+                  U1:=0;
                   U2:=0;
                   end
                 else
Index: packages/fcl-json/tests/testjsondata.pp
===================================================================
--- packages/fcl-json/tests/testjsondata.pp	(revision 48960)
+++ packages/fcl-json/tests/testjsondata.pp	(working copy)
@@ -4077,6 +4077,9 @@
   TestFrom('\u00f8','ø'); // this is ø
   TestFrom('\u00f8\"','ø"'); // this is ø"
   TestFrom('\ud83c\udf1f',GlowingStar);
+  TestFrom('\u0041\u0042','AB');   //issue #0038622
+  TestFrom('\u0041\u0042\u0043','ABC');
+  TestFrom('\u0041\u0042\u0043\u0044','ABCD');
 end;
 
 procedure TTestJSONString.TestStringToJSONString;
jsonstringtostring.diff (1,114 bytes)   

Michael Van Canneyt

2021-03-14 15:16

administrator   ~0129654

Checked and applied, thank you very much !

Bart Broersma

2021-03-14 17:16

reporter   ~0129663

Last edited: 2021-03-14 22:54

View 2 revisions

Target 4.0 ?
It would be nice it this could be backported to 3.2 fixes branch.

Bart Broersma

2021-03-14 22:55

reporter   ~0129673

Will be merged to 3.2 fixes (as per Michael on ML).

Issue History

Date Modified Username Field Change
2021-03-14 15:04 Bart Broersma New Issue
2021-03-14 15:10 Bart Broersma Note Added: 0129653
2021-03-14 15:10 Bart Broersma File Added: jsonstringtostring.diff
2021-03-14 15:14 Michael Van Canneyt Assigned To => Michael Van Canneyt
2021-03-14 15:14 Michael Van Canneyt Status new => assigned
2021-03-14 15:16 Michael Van Canneyt Status assigned => resolved
2021-03-14 15:16 Michael Van Canneyt Resolution open => fixed
2021-03-14 15:16 Michael Van Canneyt Fixed in Version => 3.3.1
2021-03-14 15:16 Michael Van Canneyt Fixed in Revision => 48962
2021-03-14 15:16 Michael Van Canneyt FPCTarget => 4.0.0
2021-03-14 15:16 Michael Van Canneyt Note Added: 0129654
2021-03-14 15:31 Michael Van Canneyt Relationship added related to 0038618
2021-03-14 17:16 Bart Broersma Note Added: 0129663
2021-03-14 22:54 Bart Broersma Note Edited: 0129663 View Revisions
2021-03-14 22:55 Bart Broersma Status resolved => closed
2021-03-14 22:55 Bart Broersma Note Added: 0129673