Skip to content

Commit

Permalink
improve base64 encoding of empty strings; docs; tag for release
Browse files Browse the repository at this point in the history
  • Loading branch information
gggeek committed Dec 19, 2022
1 parent 57a7f68 commit bb68bdb
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 12 deletions.
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## JS-XMLRPC version 0.6.1 - 2022/12/19

* fixed: `base64_encode('')` returns an empty string on all environments
* improvement: `visualeditor.html?params=` will not preload the dialog with an empty parameter


## JS-XMLRPC version 0.6.0 - 2022/12/17

* BREAKING CHANGE: transformed the library in an ES6 module, available as NPM package "@jsxmlrpc/jsxmlrpc".
Expand Down
2 changes: 1 addition & 1 deletion debugger/debugger.html
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ <h3>Notices</h3>

<h3>Changelog</h3>
<ul>
<li>ver 0.6 - 2022/12/XX: removed unsupported handling of cookies; request/response compression; timeout</li>
<li>ver 0.6 - 2022/12/17: removed unsupported handling of cookies; request/response compression; timeout</li>
</ul>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions doc/xmlrpc_js.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ JS-XMLRPC User manual
<book lang="en">
<title>JS-XMLRPC</title>

<subtitle>version 0.6</subtitle>
<subtitle>version 0.6.1</subtitle>

<bookinfo>
<date>XX 12 2012</date>
<date>19 12 2012</date>

<author>
<surname>Gaetano Giunta</surname>
Expand Down
19 changes: 11 additions & 8 deletions lib/xmlrpc_lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export var xmlrpcName = 'XML-RPC for JAVASCRIPT';
* Library version number. Used in the client's httprequests to identify self to server
* @type string
*/
export var xmlrpcVersion = '0.6';
export var xmlrpcVersion = '0.6.1';

// let user errors start at 800
export var xmlrpcerruser = 800;
Expand Down Expand Up @@ -2273,7 +2273,7 @@ export function xmlrpc_decode_xml(xml_val, options)
export function base64_decode (aString)
{
aString = aString.replace(/^\s+|\s+$/g, "");
if ((aString.length % 4) == 0)
if ((aString.length % 4) === 0)
{
if (typeof atob === 'function')
{
Expand Down Expand Up @@ -2313,7 +2313,6 @@ export function base64_decode (aString)
* @param {string} aString
* @type string
* @public
* @bug given an empty string, returns '0' in IE and Opera
*/
export function base64_encode (aString)
{
Expand All @@ -2324,35 +2323,39 @@ export function base64_encode (aString)
}
else
{
if (aString === '') {
return '';
}

var base64 = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',
'0','1','2','3','4','5','6','7','8','9','+','/'];
var sbin;
var pad = 0;
var s = '' + aString;
if ((s.length % 3) == 1)
if ((s.length % 3) === 1)
{
s += String.fromCharCode(0);
s += String.fromCharCode(0);
pad = 2;
}
else if ((s.length % 3) == 2)
else if ((s.length % 3) === 2)
{
s += String.fromCharCode(0);
pad = 1 ;
}
// create a result buffer, this is much faster than having strings concatenated
var rslt = [s.length / 3];
var rslt = [s.length / 3]; /// @todo why do we use s.length / 3 here ?
var ri = 0;
for(var i = 0; i < s.length; i += 3)
for (var i = 0; i < s.length; i += 3)
{
sbin = ((s.charCodeAt(i) & 0xff) << 16) | ((s.charCodeAt(i+1) & 0xff) << 8) | (s.charCodeAt(i+2) & 0xff);
rslt[ri] = (base64[(sbin >> 18) & 0x3f] + base64[(sbin >> 12) & 0x3f] + base64[(sbin >>6) & 0x3f] + base64[sbin & 0x3f]);
ri++;
}
if (pad > 0)
{
rslt[rslt.length-1] = rslt[rslt.length-1].substr(0, 4-pad) +((pad==2) ? '==' : (pad==1) ? '=' : '');
rslt[rslt.length-1] = rslt[rslt.length-1].substr(0, 4-pad) + ((pad === 2) ? '==' : (pad === 1) ? '=' : '');
}
return rslt.join('');
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jsxmlrpc/jsxmlrpc",
"version": "0.6.0",
"version": "0.6.1",
"description": "A javascript library for building xmlrpc and jsonrpc clients",
"keywords": [
"xmlrpc",
Expand Down

0 comments on commit bb68bdb

Please sign in to comment.