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










share|improve this question



















  • 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















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










share|improve this question



















  • 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













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










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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













  • 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













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.






share|improve this answer



























    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.






    share|improve this answer




















      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
      );



      );













      draft saved

      draft discarded


















      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.






      share|improve this answer
























        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.






        share|improve this answer






















          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.






          share|improve this answer












          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.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Apr 15 '17 at 9:32









          James Li

          111




          111






















              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.






              share|improve this answer
























                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.






                share|improve this answer






















                  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.






                  share|improve this answer












                  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.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 9 at 16:15









                  Pavel Katalymov

                  1




                  1



























                      draft saved

                      draft discarded
















































                      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.




                      draft saved


                      draft discarded














                      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





















































                      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







                      Popular posts from this blog

                      𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

                      Crossroads (UK TV series)

                      ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế