Hi Dakshitha/Jerad,

Any thoughts on the above situation ?

Thanks and Regards.
Kamidu Sachith Punchihewa
*Software Engineer*
WSO2, Inc.
lean . enterprise . middleware
Mobile : +94 (0) 770566749 <%2B94%20%280%29%20773%20451194>


Disclaimer: This communication may contain privileged or other confidential
information and is intended exclusively for the addressee/s. If you are not
the intended recipient/s, or believe that you may have received this
communication in error, please reply to the sender indicating that fact and
delete the copy you received and in addition, you should not print, copy,
retransmit, disseminate, or otherwise use the information contained in this
communication. Internet communications cannot be guaranteed to be timely,
secure, error or virus-free. The sender does not accept liability for any
errors or omissions.

---------- Forwarded message ----------
From: Kamidu Punchihewa <sachi...@wso2.com>
Date: Mon, Feb 15, 2016 at 11:40 AM
Subject: [Dev][Encoding Special Charactors] Throws an Character Out Of
Range exception
To: WSO2 Developers' List <dev@wso2.org>


Hi All,

When Encoding String including special / Latin characters throws an
Character Out Of Range exception when we use *encodeURIComponent and
decodeURIComponent* methods which was recommended to used behalf of  *escape
and unescape* since there are deprecated.
Using *escape and unescape* does not cause the above issues and Mozilla
Developer Network Publication[1] still encourage to use *escape and
unescape *alone with the *encodeURIComponent and decodeURIComponent. *

Recommended Approach is given below.

function utf8_to_b64(str) {
    return window.btoa(escape(encodeURIComponent(str)));}
function b64_to_utf8(str) {
    return decodeURIComponent(unescape(window.atob(str)));}


If we replace *escape and unescape with **encodeURIComponent and
decodeURIComponent *the functions seems recursive as given below.

function utf8_to_b64(str) {
    return window.btoa(encodeURIComponent(encodeURIComponent(str)));
}
function b64_to_utf8(str) {
    return decodeURIComponent(decodeURIComponent(window.atob(str)));
}

Which is the most appropriate way of utilising the above function?

[1].https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/btoa

Thanks & Best Regards.
Kamidu Sachith Punchihewa
*Software Engineer*
WSO2, Inc.
lean . enterprise . middleware
Mobile : +94 (0) 770566749 <%2B94%20%280%29%20773%20451194>


Disclaimer: This communication may contain privileged or other confidential
information and is intended exclusively for the addressee/s. If you are not
the intended recipient/s, or believe that you may have received this
communication in error, please reply to the sender indicating that fact and
delete the copy you received and in addition, you should not print, copy,
retransmit, disseminate, or otherwise use the information contained in this
communication. Internet communications cannot be guaranteed to be timely,
secure, error or virus-free. The sender does not accept liability for any
errors or omissions.
_______________________________________________
Dev mailing list
Dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to