Quellcode durchsuchen

* handle rawbytestrings in Win32Ansi2UnicodeMove properly, resolves #38299

git-svn-id: trunk@48021 -
florian vor 4 Jahren
Ursprung
Commit
7d5b0d2382
3 geänderte Dateien mit 24 neuen und 0 gelöschten Zeilen
  1. 1 0
      .gitattributes
  2. 8 0
      rtl/win/syswin.inc
  3. 15 0
      tests/webtbs/tw38299.pp

+ 1 - 0
.gitattributes

@@ -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

+ 8 - 0
rtl/win/syswin.inc

@@ -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 - 0
tests/webtbs/tw38299.pp

@@ -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.