#1 2020-02-17 08:20:25

sakura
Member
From: Germany
Registered: 2018-02-21
Posts: 228
Website

UrlEncodeJsonObject regression

Hi,

a quiet simple call to UrlEncodeJsonObject will fail in an exception (Delphi 10.3.3).

Sample project:

program Project2;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  SynCommons,
  System.SysUtils;

procedure Test;
var
  SendDataJSON, SendDataEncoded: RawUTF8;
begin
  SendDataJSON := '{"b":30,"a":12}';
  SendDataEncoded := UrlEncodeJsonObject('', PUTF8Char(SendDataJSON), []);

  Writeln(SendDataEncoded);
end;

begin
  try
    Test;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;

  Readln;
end.

Offline

#2 2020-02-17 08:21:26

sakura
Member
From: Germany
Registered: 2018-02-21
Posts: 228
Website

Re: UrlEncodeJsonObject regression

Worked with prior releases (from about a week ago), just pulled the most recent updates from GIT and it's not working as expected.

Last edited by sakura (2020-02-17 08:23:41)

Offline

#3 2020-02-17 09:14:01

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,238
Website

Re: UrlEncodeJsonObject regression

The problem is that the JSON input is modified in place: it needs to be copied before parsing in your case, since SendDatAJSON is a read-only string.
If you write @SendDataJSON[1] it should make a copy and let the test pass - at least with Delphi.

I have made it explicit in the doc, and written an overloaded function which makes the copy.
See https://synopse.info/fossil/info/668368aeba

Offline

#4 2020-02-17 09:33:50

sakura
Member
From: Germany
Registered: 2018-02-21
Posts: 228
Website

Re: UrlEncodeJsonObject regression

Okay, that I should have noticed, when it showed the place, where it failed. Interesting though, that it worked so far, always. Thanks.

Offline

Board footer

Powered by FluxBB