Parcourir la source

* when inserting a non-empty ansistring into an empty ansistring, the
destination must get the code page of the source (mantis #28850)

git-svn-id: trunk@32066 -

Jonas Maebe il y a 9 ans
Parent
commit
1294dc1ede
3 fichiers modifiés avec 25 ajouts et 1 suppressions
  1. 1 0
      .gitattributes
  2. 4 1
      rtl/inc/astrings.inc
  3. 20 0
      tests/webtbs/tw28850.pp

+ 1 - 0
.gitattributes

@@ -14764,6 +14764,7 @@ tests/webtbs/tw2876.pp svneol=native#text/plain
 tests/webtbs/tw28766.pp svneol=native#text/pascal
 tests/webtbs/tw2883.pp svneol=native#text/plain
 tests/webtbs/tw2885.pp svneol=native#text/plain
+tests/webtbs/tw28850.pp svneol=native#text/plain
 tests/webtbs/tw2886.pp svneol=native#text/plain
 tests/webtbs/tw2891.pp svneol=native#text/plain
 tests/webtbs/tw2892.pp svneol=native#text/plain

+ 4 - 1
rtl/inc/astrings.inc

@@ -1384,7 +1384,10 @@ begin
    index := LS+1;
   Dec(Index);
   SetLength(Temp,Length(Source)+LS);
-  cp:=TranslatePlaceholderCP(StringCodePage(S));
+  if length(S)<>0 then
+    cp:=TranslatePlaceholderCP(StringCodePage(S))
+  else
+    cp:=TranslatePlaceholderCP(StringCodePage(Source));
   SetCodePage(Temp,cp,false);
   If Index>0 then
     fpc_pchar_ansistr_intern_charmove(pchar(S),0,Temp,0,Index);

+ 20 - 0
tests/webtbs/tw28850.pp

@@ -0,0 +1,20 @@
+var
+  s1, s2: ansistring;
+begin
+  s1 := 'abc';
+  s2:='';
+  { ensure the codepage of s1 is different from defaultsystemcodepage }
+  if defaultsystemcodepage=866 then
+    setcodepage(rawbytestring(s1),1251,false)
+  else
+    setcodepage(rawbytestring(s1),866,false); 
+  { if the destination is empty, insert must create a new string
+    with the same code page as the source }
+  Insert(s1, s2, 1);
+  if StringRefCount(s1)<>1 then
+    halt(1);
+  if StringRefCount(s2)<>1 then
+    halt(2);
+  if stringcodepage(s2)<>stringcodepage(s1) then
+    halt(3);
+end.