* handle rawbytestrings in Win32Ansi2UnicodeMove properly, resolves #38299

git-svn-id: trunk@48021 -
This commit is contained in:
florian 2021-01-03 22:55:37 +00:00
parent f2568e37e4
commit 7d5b0d2382
3 changed files with 24 additions and 0 deletions

1
.gitattributes vendored
View File

@ -18631,6 +18631,7 @@ tests/webtbs/tw38267b.pp svneol=native#text/pascal
tests/webtbs/tw3827.pp svneol=native#text/plain
tests/webtbs/tw3829.pp svneol=native#text/plain
tests/webtbs/tw38295.pp svneol=native#text/pascal
tests/webtbs/tw38299.pp svneol=native#text/pascal
tests/webtbs/tw3833.pp svneol=native#text/plain
tests/webtbs/tw3840.pp svneol=native#text/plain
tests/webtbs/tw3841.pp svneol=native#text/plain

View File

@ -609,6 +609,14 @@ procedure Win32Ansi2UnicodeMove(source:pchar;cp : TSystemCodePage;var dest:Unico
dwFlags:=MB_PRECOMPOSED;
end;
destlen:=MultiByteToWideChar(cp, dwFlags, source, len, nil, 0);
{ destlen=0 means that Windows cannot convert, so call the default
handler. This is similiar to what unix does and is a good fallback
if rawbyte strings are passed }
if destlen=0 then
begin
DefaultAnsi2UnicodeMove(source,DefaultSystemCodePage,dest,len);
exit;
end;
// this will null-terminate
setlength(dest, destlen);
if destlen>0 then

15
tests/webtbs/tw38299.pp Normal file
View File

@ -0,0 +1,15 @@
{ %opt=-O2 -Fcutf8 }
program bug;
const
cAnsiLineFeed = AnsiChar(#10);
cAnsiCarriageReturn = AnsiChar(#13);
var
test: RawByteString;
begin
test := '123';
test := test + UTF8Encode('456') + '789' + cAnsiCarriageReturn + cAnsiLineFeed;
writeln(test);
if test<>'123456789'#13#10 then
halt(1);
writeln('ok');
end.