Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2021-03

JSONStringToString question

11 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Bart

Function result
Pascal string with escaped characters replaced

{$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.2.0 [2020/06/04] for i386 Copyright (c) 1993-2020 by Florian Klaempfl and others Target OS: Win32 for i386
Compiling test.pas
Linking test.exe
15 lines compiled, 0.2 sec, 233536 bytes code, 10196 bytes data

C:\Users\Bart\LazarusProjecten\ConsoleProjecten>test S: \u0041\
A (as expected)
S: \u0042
B (as expected)
S: \"\u0041\
"A (as expected)
S: \"\u0041\"
"A" (as expected)
S: \u0041\u0042
AAB (Huh??)

Do I misunderstand the purpose of this function or is this a bug?

Bart

Reply by email

Michael Van Canneyt
to Bart
Bart wrote 41 lines
From : https://www.freepascal.org/docs-html/current/fcl/fpjson/jsonstringtostring.html Function result Pascal string with escaped characters replaced {$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.2.0 [2020/06/04] for i386 Copyright (c) 1993-2020 by Florian Klaempfl and others Target OS: Win32 for i386 Compiling test.pas Linking test.exe 15 lines compiled, 0.2 sec, 233536 bytes code, 10196 bytes data C:\Users\Bart\LazarusProjecten\ConsoleProjecten>test S: \u0041\ A (as expected) S: \u0042 B (as expected) S: \"\u0041\ "A (as expected) S: \"\u0041\" "A" (as expected) S: \u0041\u0042 AAB (Huh??) Do I misunderstand the purpose of this function or is this a bug?

Seems like a bug.

Michael.

Reply by email

Bart
to Michael Van Canneyt
AM Michael Van Canneyt wrote
> Do I misunderstand the purpose of this function or is this a bug? Seems like a bug.

I'll report it then.
Do you know if we have a test suite for this function, so I can test if there ar regressions when I try to fix it?

Bart

Reply by email

Bart
to Bart
PM Bart wrote
Do you know if we have a test suite for this function, so I can test if there ar regressions when I try to fix it?

Found it already.
I think I have a fix, will report it.

Bart

Reply by email

Michael Van Canneyt
to Bart: On Sun, Mar 14, 2021 at 12:43 AM Michael Van Canneyt via fpc-pascal I'll report it then.…
Bart wrote 10 lines
On Sun, Mar 14, 2021 at 12:43 AM Michael Van Canneyt via fpc-pascal wrote: > > Do I misunderstand the purpose of this function or is this a bug? > > Seems like a bug. I'll report it then. Do you know if we have a test suite for this function, so I can test if there ar regressions when I try to fix it?

The JSON classes use this function.
There is a JSON testsuite. Just run that.

Michael.

Reply by email

Michael Van Canneyt
to Bart
Bart wrote 8 lines
On Sun, Mar 14, 2021 at 4:15 PM Michael Van Canneyt via fpc-pascal wrote: > Fixed. Thanks for the patch. > There was a second issue, which is now also fixed. You set target to fpc 4.0 The simple patch I made can be backported/merged to 3.2 fixes branch?

Well, 4.0 is the only "future" version.
There is not yet a 3.2.4 planned.
We don't know what the next version is, so I chose what is available.

Michael.

Reply by email

Sven Barth
to Michael Van Canneyt

Michael Van Canneyt via fpc-pascal
schrieb am So., 14. März 2021, 18:03:

Show quoted text 17 lines
On Sun, 14 Mar 2021, Bart via fpc-pascal wrote: > On Sun, Mar 14, 2021 at 4:15 PM Michael Van Canneyt via fpc-pascal > wrote: > >> Fixed. Thanks for the patch. >> There was a second issue, which is now also fixed. > > You set target to fpc 4.0 > The simple patch I made can be backported/merged to 3.2 fixes branch? Well, 4.0 is the only "future" version. There is not yet a 3.2.4 planned. We don't know what the next version is, so I chose what is available.

Why not merge it to 3.2.1 regardless? After all we'll tag the final 3.2.2 from the fixes branch again and there are already some other fixes that will be in the final that aren't in the RC yet.

Regards,
Sven

Reply by email

Michael Van Canneyt
to Sven Barth
Sven Barth wrote 17 lines
>> On Sun, Mar 14, 2021 at 4:15 PM Michael Van Canneyt via fpc-pascal >> wrote: >> >>> Fixed. Thanks for the patch. >>> There was a second issue, which is now also fixed. >> >> You set target to fpc 4.0 >> The simple patch I made can be backported/merged to 3.2 fixes branch? > > Well, 4.0 is the only "future" version. > There is not yet a 3.2.4 planned. > We don't know what the next version is, so I chose what is available. > Why not merge it to 3.2.1 regardless? After all we'll tag the final 3.2.2 from the fixes branch again and there are already some other fixes that will be in the final that aren't in the RC yet.

No worries; I was planning to merge to fixes.

But whether it should be in 3.2.2, I don't know yet, there is a related bugreport which indicates that the bug is deeper than expected.

In each case, there is no 3.2.4, so currently 4.0 is the only future version. I mark all bugs I fix for that version currently.

Michael.

Reply by email