mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-11 09:26:15 +02:00
fcl-js: fixed escaping invalid UTF-16 i string literals
git-svn-id: trunk@40191 -
This commit is contained in:
parent
9b0ff05ee8
commit
f0e75cdbbb
@ -176,6 +176,7 @@ begin
|
|||||||
else
|
else
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
|
Result:=true;
|
||||||
end;
|
end;
|
||||||
{$else}
|
{$else}
|
||||||
var
|
var
|
||||||
|
@ -534,8 +534,8 @@ Var
|
|||||||
I,J,L : Integer;
|
I,J,L : Integer;
|
||||||
R: TJSString;
|
R: TJSString;
|
||||||
c: WideChar;
|
c: WideChar;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
//system.writeln('TJSWriter.EscapeString "',S,'"');
|
||||||
I:=1;
|
I:=1;
|
||||||
J:=1;
|
J:=1;
|
||||||
R:='';
|
R:='';
|
||||||
@ -543,7 +543,8 @@ begin
|
|||||||
While I<=L do
|
While I<=L do
|
||||||
begin
|
begin
|
||||||
c:=S[I];
|
c:=S[I];
|
||||||
if (c in [#0..#31,'"','''','/','\']) or (c>=#$ff00) then
|
if (c in [#0..#31,'"','''','/','\'])
|
||||||
|
or (c>=#$ff00) or ((c>=#$D800) and (c<=#$DFFF)) then
|
||||||
begin
|
begin
|
||||||
R:=R+Copy(S,J,I-J);
|
R:=R+Copy(S,J,I-J);
|
||||||
Case c of
|
Case c of
|
||||||
@ -557,7 +558,25 @@ begin
|
|||||||
#10 : R:=R+'\n';
|
#10 : R:=R+'\n';
|
||||||
#12 : R:=R+'\f';
|
#12 : R:=R+'\f';
|
||||||
#13 : R:=R+'\r';
|
#13 : R:=R+'\r';
|
||||||
#$ff00..#$ffff: R:=R+'\u'+TJSString(HexStr(ord(c),4));
|
#$D800..#$DFFF:
|
||||||
|
begin
|
||||||
|
if (I<L) then
|
||||||
|
begin
|
||||||
|
c:=S[I+1];
|
||||||
|
if (c>=#$D000) and (c<=#$DFFF) then
|
||||||
|
begin
|
||||||
|
inc(I,2); // surrogate, two char codepoint
|
||||||
|
continue;
|
||||||
|
end
|
||||||
|
else
|
||||||
|
// invalid UTF-16, cannot be encoded as UTF-8 -> encode as hex
|
||||||
|
R:=R+'\u'+TJSString(HexStr(ord(c),4));
|
||||||
|
end
|
||||||
|
else
|
||||||
|
// invalid UTF-16 at end of string, cannot be encoded as UTF-8 -> encode as hex
|
||||||
|
R:=R+'\u'+TJSString(HexStr(ord(c),4));
|
||||||
|
end;
|
||||||
|
#$FF00..#$FFFF: R:=R+'\u'+TJSString(HexStr(ord(c),4));
|
||||||
end;
|
end;
|
||||||
J:=I+1;
|
J:=I+1;
|
||||||
end;
|
end;
|
||||||
@ -565,6 +584,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
R:=R+Copy(S,J,I-1);
|
R:=R+Copy(S,J,I-1);
|
||||||
Result:=R;
|
Result:=R;
|
||||||
|
//system.writeln('TJSWriter.EscapeString Result="',Result,'"');
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TJSWriter.WriteValue(V: TJSValue);
|
procedure TJSWriter.WriteValue(V: TJSValue);
|
||||||
|
Loading…
Reference in New Issue
Block a user