No mapping for the Unicode character exists in the target multi-byte code page
up vote
2
down vote
favorite
i have a soap builded with Delphi 2007 and it work!
After a conversion in Delphi 10.1 Berlin i have a lot of exceptions:
No mapping for the Unicode character exists in the target multi-byte code page
the cause seem, when webbroker HttpApp parsing the request parameters, it raise this exception if request has some url encoded chars in the query string, eg.:
http://localhost/soap/soap.dll/action?param=%E0
in fact if i call URL.Decode()
with %E0
(à
url encoded):
TNetEncoding.URL.Decode('%E0');
it raise the same exception:
No mapping for the Unicode character exists in the target multi-byte code page
The problem seem unit System.NetEncoding
on method TURLEncoding.DoDecode(const Input: string): string
. This method try to convert url encoded chars only in UTF-8 without any fallback on Windows-1252. String %E0
is Windows-1252 encoding for à
, but delphi only conver UTF-8 version: %C3%A0
.
A small (not perfect, not elegant) fix is add a fallback:
try
Result := TEncoding.UTF8.GetString(Bytes); // original Delphi 10.1 line
except
on E: EEncodingError do Result := string(PChar(Bytes)); // fallback
end;
full code:
function TURLEncoding.DoDecode(const Input: string): string;
function DecodeHexChar(const C: Char): Byte;
begin
case C of
'0'..'9': Result := Ord(C) - Ord('0');
'A'..'F': Result := Ord(C) - Ord('A') + 10;
'a'..'f': Result := Ord(C) - Ord('a') + 10;
else
raise EConvertError.Create('');
end;
end;
function DecodeHexPair(const C1, C2: Char): Byte; inline;
begin
Result := DecodeHexChar(C1) shl 4 + DecodeHexChar(C2)
end;
var
Sp, Cp: PChar;
I: Integer;
Bytes: TBytes;
begin
SetLength(Bytes, Length(Input) * 4);
I := 0;
Sp := PChar(Input);
Cp := Sp;
try
while Sp^ <> #0 do
begin
case Sp^ of
'+':
Bytes[I] := Byte(' ');
'%':
begin
Inc(Sp);
// Look for an escaped % (%%)
if (Sp)^ = '%' then
Bytes[I] := Byte('%')
else
begin
// Get an encoded byte, may is a single byte (%<hex>)
// or part of multi byte (%<hex>%<hex>...) character
Cp := Sp;
Inc(Sp);
if ((Cp^ = #0) or (Sp^ = #0)) then
raise EHTTPException.CreateFmt(sErrorDecodingURLText, [Cp - PChar(Input)]);
Bytes[I] := DecodeHexPair(Cp^, Sp^)
end;
end;
else
// Accept single and multi byte characters
if Ord(Sp^) < 128 then
Bytes[I] := Byte(Sp^)
else
I := I + TEncoding.UTF8.GetBytes([Sp^], 0, 1, Bytes, I) - 1
end;
Inc(I);
Inc(Sp);
end;
except
on E: EConvertError do
raise EConvertError.CreateFmt(sInvalidURLEncodedChar, [Char('%') + Cp^ + Sp^, Cp - PChar(Input)])
end;
SetLength(Bytes, I);
// ------> MY FIX <------
try
Result := TEncoding.UTF8.GetString(Bytes); // Original line
except
on E: EEncodingError do Result := string(PChar(Bytes));
end;
// END FIX
end;
After a lot of search i founds the Bug fix list for RAD Studio 10.1 Berlin and it says this bug is fixed:
Webbroker HttpApp parsing request parameters and getting error "No mapping for the Unicode character exists in the target multi-byte code page"
but not work for me...
delphi utf-8 urlencode delphi-10.1-berlin webbroker
add a comment |
up vote
2
down vote
favorite
i have a soap builded with Delphi 2007 and it work!
After a conversion in Delphi 10.1 Berlin i have a lot of exceptions:
No mapping for the Unicode character exists in the target multi-byte code page
the cause seem, when webbroker HttpApp parsing the request parameters, it raise this exception if request has some url encoded chars in the query string, eg.:
http://localhost/soap/soap.dll/action?param=%E0
in fact if i call URL.Decode()
with %E0
(à
url encoded):
TNetEncoding.URL.Decode('%E0');
it raise the same exception:
No mapping for the Unicode character exists in the target multi-byte code page
The problem seem unit System.NetEncoding
on method TURLEncoding.DoDecode(const Input: string): string
. This method try to convert url encoded chars only in UTF-8 without any fallback on Windows-1252. String %E0
is Windows-1252 encoding for à
, but delphi only conver UTF-8 version: %C3%A0
.
A small (not perfect, not elegant) fix is add a fallback:
try
Result := TEncoding.UTF8.GetString(Bytes); // original Delphi 10.1 line
except
on E: EEncodingError do Result := string(PChar(Bytes)); // fallback
end;
full code:
function TURLEncoding.DoDecode(const Input: string): string;
function DecodeHexChar(const C: Char): Byte;
begin
case C of
'0'..'9': Result := Ord(C) - Ord('0');
'A'..'F': Result := Ord(C) - Ord('A') + 10;
'a'..'f': Result := Ord(C) - Ord('a') + 10;
else
raise EConvertError.Create('');
end;
end;
function DecodeHexPair(const C1, C2: Char): Byte; inline;
begin
Result := DecodeHexChar(C1) shl 4 + DecodeHexChar(C2)
end;
var
Sp, Cp: PChar;
I: Integer;
Bytes: TBytes;
begin
SetLength(Bytes, Length(Input) * 4);
I := 0;
Sp := PChar(Input);
Cp := Sp;
try
while Sp^ <> #0 do
begin
case Sp^ of
'+':
Bytes[I] := Byte(' ');
'%':
begin
Inc(Sp);
// Look for an escaped % (%%)
if (Sp)^ = '%' then
Bytes[I] := Byte('%')
else
begin
// Get an encoded byte, may is a single byte (%<hex>)
// or part of multi byte (%<hex>%<hex>...) character
Cp := Sp;
Inc(Sp);
if ((Cp^ = #0) or (Sp^ = #0)) then
raise EHTTPException.CreateFmt(sErrorDecodingURLText, [Cp - PChar(Input)]);
Bytes[I] := DecodeHexPair(Cp^, Sp^)
end;
end;
else
// Accept single and multi byte characters
if Ord(Sp^) < 128 then
Bytes[I] := Byte(Sp^)
else
I := I + TEncoding.UTF8.GetBytes([Sp^], 0, 1, Bytes, I) - 1
end;
Inc(I);
Inc(Sp);
end;
except
on E: EConvertError do
raise EConvertError.CreateFmt(sInvalidURLEncodedChar, [Char('%') + Cp^ + Sp^, Cp - PChar(Input)])
end;
SetLength(Bytes, I);
// ------> MY FIX <------
try
Result := TEncoding.UTF8.GetString(Bytes); // Original line
except
on E: EEncodingError do Result := string(PChar(Bytes));
end;
// END FIX
end;
After a lot of search i founds the Bug fix list for RAD Studio 10.1 Berlin and it says this bug is fixed:
Webbroker HttpApp parsing request parameters and getting error "No mapping for the Unicode character exists in the target multi-byte code page"
but not work for me...
delphi utf-8 urlencode delphi-10.1-berlin webbroker
1
Just an FYI, there is no such thing as Delphi XE 10.1 - it's just Delphi 10.1 Berlin. Updated your tags.
– Jerry Dodge
Nov 8 '16 at 15:02
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
i have a soap builded with Delphi 2007 and it work!
After a conversion in Delphi 10.1 Berlin i have a lot of exceptions:
No mapping for the Unicode character exists in the target multi-byte code page
the cause seem, when webbroker HttpApp parsing the request parameters, it raise this exception if request has some url encoded chars in the query string, eg.:
http://localhost/soap/soap.dll/action?param=%E0
in fact if i call URL.Decode()
with %E0
(à
url encoded):
TNetEncoding.URL.Decode('%E0');
it raise the same exception:
No mapping for the Unicode character exists in the target multi-byte code page
The problem seem unit System.NetEncoding
on method TURLEncoding.DoDecode(const Input: string): string
. This method try to convert url encoded chars only in UTF-8 without any fallback on Windows-1252. String %E0
is Windows-1252 encoding for à
, but delphi only conver UTF-8 version: %C3%A0
.
A small (not perfect, not elegant) fix is add a fallback:
try
Result := TEncoding.UTF8.GetString(Bytes); // original Delphi 10.1 line
except
on E: EEncodingError do Result := string(PChar(Bytes)); // fallback
end;
full code:
function TURLEncoding.DoDecode(const Input: string): string;
function DecodeHexChar(const C: Char): Byte;
begin
case C of
'0'..'9': Result := Ord(C) - Ord('0');
'A'..'F': Result := Ord(C) - Ord('A') + 10;
'a'..'f': Result := Ord(C) - Ord('a') + 10;
else
raise EConvertError.Create('');
end;
end;
function DecodeHexPair(const C1, C2: Char): Byte; inline;
begin
Result := DecodeHexChar(C1) shl 4 + DecodeHexChar(C2)
end;
var
Sp, Cp: PChar;
I: Integer;
Bytes: TBytes;
begin
SetLength(Bytes, Length(Input) * 4);
I := 0;
Sp := PChar(Input);
Cp := Sp;
try
while Sp^ <> #0 do
begin
case Sp^ of
'+':
Bytes[I] := Byte(' ');
'%':
begin
Inc(Sp);
// Look for an escaped % (%%)
if (Sp)^ = '%' then
Bytes[I] := Byte('%')
else
begin
// Get an encoded byte, may is a single byte (%<hex>)
// or part of multi byte (%<hex>%<hex>...) character
Cp := Sp;
Inc(Sp);
if ((Cp^ = #0) or (Sp^ = #0)) then
raise EHTTPException.CreateFmt(sErrorDecodingURLText, [Cp - PChar(Input)]);
Bytes[I] := DecodeHexPair(Cp^, Sp^)
end;
end;
else
// Accept single and multi byte characters
if Ord(Sp^) < 128 then
Bytes[I] := Byte(Sp^)
else
I := I + TEncoding.UTF8.GetBytes([Sp^], 0, 1, Bytes, I) - 1
end;
Inc(I);
Inc(Sp);
end;
except
on E: EConvertError do
raise EConvertError.CreateFmt(sInvalidURLEncodedChar, [Char('%') + Cp^ + Sp^, Cp - PChar(Input)])
end;
SetLength(Bytes, I);
// ------> MY FIX <------
try
Result := TEncoding.UTF8.GetString(Bytes); // Original line
except
on E: EEncodingError do Result := string(PChar(Bytes));
end;
// END FIX
end;
After a lot of search i founds the Bug fix list for RAD Studio 10.1 Berlin and it says this bug is fixed:
Webbroker HttpApp parsing request parameters and getting error "No mapping for the Unicode character exists in the target multi-byte code page"
but not work for me...
delphi utf-8 urlencode delphi-10.1-berlin webbroker
i have a soap builded with Delphi 2007 and it work!
After a conversion in Delphi 10.1 Berlin i have a lot of exceptions:
No mapping for the Unicode character exists in the target multi-byte code page
the cause seem, when webbroker HttpApp parsing the request parameters, it raise this exception if request has some url encoded chars in the query string, eg.:
http://localhost/soap/soap.dll/action?param=%E0
in fact if i call URL.Decode()
with %E0
(à
url encoded):
TNetEncoding.URL.Decode('%E0');
it raise the same exception:
No mapping for the Unicode character exists in the target multi-byte code page
The problem seem unit System.NetEncoding
on method TURLEncoding.DoDecode(const Input: string): string
. This method try to convert url encoded chars only in UTF-8 without any fallback on Windows-1252. String %E0
is Windows-1252 encoding for à
, but delphi only conver UTF-8 version: %C3%A0
.
A small (not perfect, not elegant) fix is add a fallback:
try
Result := TEncoding.UTF8.GetString(Bytes); // original Delphi 10.1 line
except
on E: EEncodingError do Result := string(PChar(Bytes)); // fallback
end;
full code:
function TURLEncoding.DoDecode(const Input: string): string;
function DecodeHexChar(const C: Char): Byte;
begin
case C of
'0'..'9': Result := Ord(C) - Ord('0');
'A'..'F': Result := Ord(C) - Ord('A') + 10;
'a'..'f': Result := Ord(C) - Ord('a') + 10;
else
raise EConvertError.Create('');
end;
end;
function DecodeHexPair(const C1, C2: Char): Byte; inline;
begin
Result := DecodeHexChar(C1) shl 4 + DecodeHexChar(C2)
end;
var
Sp, Cp: PChar;
I: Integer;
Bytes: TBytes;
begin
SetLength(Bytes, Length(Input) * 4);
I := 0;
Sp := PChar(Input);
Cp := Sp;
try
while Sp^ <> #0 do
begin
case Sp^ of
'+':
Bytes[I] := Byte(' ');
'%':
begin
Inc(Sp);
// Look for an escaped % (%%)
if (Sp)^ = '%' then
Bytes[I] := Byte('%')
else
begin
// Get an encoded byte, may is a single byte (%<hex>)
// or part of multi byte (%<hex>%<hex>...) character
Cp := Sp;
Inc(Sp);
if ((Cp^ = #0) or (Sp^ = #0)) then
raise EHTTPException.CreateFmt(sErrorDecodingURLText, [Cp - PChar(Input)]);
Bytes[I] := DecodeHexPair(Cp^, Sp^)
end;
end;
else
// Accept single and multi byte characters
if Ord(Sp^) < 128 then
Bytes[I] := Byte(Sp^)
else
I := I + TEncoding.UTF8.GetBytes([Sp^], 0, 1, Bytes, I) - 1
end;
Inc(I);
Inc(Sp);
end;
except
on E: EConvertError do
raise EConvertError.CreateFmt(sInvalidURLEncodedChar, [Char('%') + Cp^ + Sp^, Cp - PChar(Input)])
end;
SetLength(Bytes, I);
// ------> MY FIX <------
try
Result := TEncoding.UTF8.GetString(Bytes); // Original line
except
on E: EEncodingError do Result := string(PChar(Bytes));
end;
// END FIX
end;
After a lot of search i founds the Bug fix list for RAD Studio 10.1 Berlin and it says this bug is fixed:
Webbroker HttpApp parsing request parameters and getting error "No mapping for the Unicode character exists in the target multi-byte code page"
but not work for me...
delphi utf-8 urlencode delphi-10.1-berlin webbroker
delphi utf-8 urlencode delphi-10.1-berlin webbroker
edited Nov 8 '16 at 15:28
asked Nov 8 '16 at 9:58
ar099968
1,1291338
1,1291338
1
Just an FYI, there is no such thing as Delphi XE 10.1 - it's just Delphi 10.1 Berlin. Updated your tags.
– Jerry Dodge
Nov 8 '16 at 15:02
add a comment |
1
Just an FYI, there is no such thing as Delphi XE 10.1 - it's just Delphi 10.1 Berlin. Updated your tags.
– Jerry Dodge
Nov 8 '16 at 15:02
1
1
Just an FYI, there is no such thing as Delphi XE 10.1 - it's just Delphi 10.1 Berlin. Updated your tags.
– Jerry Dodge
Nov 8 '16 at 15:02
Just an FYI, there is no such thing as Delphi XE 10.1 - it's just Delphi 10.1 Berlin. Updated your tags.
– Jerry Dodge
Nov 8 '16 at 15:02
add a comment |
2 Answers
2
active
oldest
votes
up vote
1
down vote
try use WEB.ReqMulti;
I have the same exception when I user WebBroker to handle a POST method from a web page when there are multi-byte character in form.
And after I added use WEB.ReqMulti in WebBroker's project, this exception was gone.
add a comment |
up vote
0
down vote
I had "No mapping for the Unicode character exists in the target multi-byte code page" exception in Tokyo (10.2.1) IDE when trying to close IDE.
To fix: delete the file .$$$ from your project's directory.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f40483888%2fno-mapping-for-the-unicode-character-exists-in-the-target-multi-byte-code-page%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
try use WEB.ReqMulti;
I have the same exception when I user WebBroker to handle a POST method from a web page when there are multi-byte character in form.
And after I added use WEB.ReqMulti in WebBroker's project, this exception was gone.
add a comment |
up vote
1
down vote
try use WEB.ReqMulti;
I have the same exception when I user WebBroker to handle a POST method from a web page when there are multi-byte character in form.
And after I added use WEB.ReqMulti in WebBroker's project, this exception was gone.
add a comment |
up vote
1
down vote
up vote
1
down vote
try use WEB.ReqMulti;
I have the same exception when I user WebBroker to handle a POST method from a web page when there are multi-byte character in form.
And after I added use WEB.ReqMulti in WebBroker's project, this exception was gone.
try use WEB.ReqMulti;
I have the same exception when I user WebBroker to handle a POST method from a web page when there are multi-byte character in form.
And after I added use WEB.ReqMulti in WebBroker's project, this exception was gone.
answered Apr 15 '17 at 9:32
James Li
111
111
add a comment |
add a comment |
up vote
0
down vote
I had "No mapping for the Unicode character exists in the target multi-byte code page" exception in Tokyo (10.2.1) IDE when trying to close IDE.
To fix: delete the file .$$$ from your project's directory.
add a comment |
up vote
0
down vote
I had "No mapping for the Unicode character exists in the target multi-byte code page" exception in Tokyo (10.2.1) IDE when trying to close IDE.
To fix: delete the file .$$$ from your project's directory.
add a comment |
up vote
0
down vote
up vote
0
down vote
I had "No mapping for the Unicode character exists in the target multi-byte code page" exception in Tokyo (10.2.1) IDE when trying to close IDE.
To fix: delete the file .$$$ from your project's directory.
I had "No mapping for the Unicode character exists in the target multi-byte code page" exception in Tokyo (10.2.1) IDE when trying to close IDE.
To fix: delete the file .$$$ from your project's directory.
answered Nov 9 at 16:15
Pavel Katalymov
1
1
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f40483888%2fno-mapping-for-the-unicode-character-exists-in-the-target-multi-byte-code-page%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Just an FYI, there is no such thing as Delphi XE 10.1 - it's just Delphi 10.1 Berlin. Updated your tags.
– Jerry Dodge
Nov 8 '16 at 15:02