#1 2022-02-28 21:53:08

HollosCs
Member
Registered: 2015-12-08
Posts: 56

Base64ToBin no return value

Hi AB!

My code not working (a couple months ago there was no problem)

function Base64ToBin(const s: RawByteString): RawByteString;
begin
  Base64ToBinSafe(pointer(s), length(s), result);
end;

The result variable is ok inside above code, but when I use this function, the return value is empty string.

  token := Base64ToBin(aToken);

Delphi 11, latest ORM

Thanks, Csaba

Last edited by HollosCs (2022-02-28 21:53:51)

Offline

#2 2022-03-01 06:26:04

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

Re: Base64ToBin no return value

Because aToken is not a valid Base-64 encoded content, I guess.
There may be some space, line feed or unexpect character within.

BTW: mORMot 1 or 2?

What is the input? Does it decode on https://www.base64decode.org/ for instance?
(please do not post it directly in this forum but on a gist/pastebin link)

Offline

#3 2022-03-01 06:48:17

HollosCs
Member
Registered: 2015-12-08
Posts: 56

Re: Base64ToBin no return value

Hi

I using mormot 2 and before couple of months is no problem.

Base64ToBin conversion is success, but no return value.

https://pastebin.com/dnhTq5KZ

Csaba

Offline

#4 2022-03-01 07:18:00

HollosCs
Member
Registered: 2015-12-08
Posts: 56

Re: Base64ToBin no return value

Seems to in string from RawByteString (string := RawByteString) conversation lost data on function result after quit function.

If I use RawByteString on full call chain, result is back.

What is the best/safe conversation RawByteString to String?

Offline

#5 2022-03-01 07:24:23

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

Re: Base64ToBin no return value

It depends on the string code page, once decoded as bin.
Is it UTF-8? Then use Utf8ToString() or Utf8ToStringVar().

On Delphi, you should make all such conversions explicit.
I guess there was a compiler warning in your source code.
Use an explicit conversion function like Utf8ToString() or Utf8ToStringVar().

In your case, your code is pretty wrong.
Don't define token:string; but token:RawByteString;
You are a little bit confused about the Delphi string types - they are somewhat difficult for sure - so consider looking at the documentation about them.

Offline

#6 2022-03-01 07:54:09

HollosCs
Member
Registered: 2015-12-08
Posts: 56

Re: Base64ToBin no return value

Thanks!
You are right, explicit conversation is required. (Perhaps change something in D11). And sorry for take yours time.
Strings are not simple.
Csaba

Offline

Board footer

Powered by FluxBB