Skip to content

Commit 46f3bb8

Browse files
committed
Fixed U.atob() + U.btoa().
1 parent b1ffe04 commit 46f3bb8

3 files changed

Lines changed: 14 additions & 6 deletions

File tree

changes.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
- fixed: `Date.format()` now it formats a date as UTC correctly
4040
- fixed: HTML compressor with `\r\n` (Windows line endings)
4141
- fixed: schema validation
42+
- fixed: `U.atob()`
43+
- fixed: `U.btoa()`
4244

4345
- improved: `debug` mode timing with improved consumption
4446

test/test-utils.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -612,12 +612,18 @@ function other() {
612612

613613
var a = { buf: Buffer.from('123456') };
614614
assert.ok(U.clone(a).buf !== a, 'Cloning buffers');
615+
616+
var input = '12345čťžýáýáííéídfsfgd';
617+
var a = U.btoa(input);
618+
var b = U.atob(a);
619+
620+
assert.ok(b === input, 'U.atob() / U.btoa()');
615621
}
616622

617623
function Utils_Ls2_StringFilter() {
618624
var result;
619625
var async = new Utils.Async();
620-
626+
621627
async.await('U.ls2', function(next) {
622628
U.ls2(
623629
'./app',
@@ -628,7 +634,7 @@ function Utils_Ls2_StringFilter() {
628634
'app'
629635
);
630636
});
631-
637+
632638
async.run(function() {
633639
assert.ok(result.files.length === 1, 'problem with number of files from U.ls2 string filter');
634640
assert.ok(result.files[0].filename.indexOf('virtual.txt') !== -1, 'problem with files[0].filename from U.ls2 string filter');
@@ -640,7 +646,7 @@ function Utils_Ls2_StringFilter() {
640646
function Utils_Ls_RegExpFilter() {
641647
var result;
642648
var async = new Utils.Async();
643-
649+
644650
async.await('U.ls', function(next) {
645651
U.ls(
646652
'./app',
@@ -651,7 +657,7 @@ function Utils_Ls_RegExpFilter() {
651657
/QQQ/
652658
);
653659
});
654-
660+
655661
async.run(function() {
656662
assert.ok(result.files.length === 0, 'problem with files from U.ls regExp filter');
657663
assert.ok(result.folders.length === 0, 'problem with folders from U.ls regExp filter');

utils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -792,11 +792,11 @@ exports.$$request = function(url, flags, data, cookies, headers, encoding, timeo
792792
};
793793

794794
exports.btoa = function(str) {
795-
return (str instanceof Buffer) ? str.toString('base64') : exports.createBuffer(str.toString(), 'binary').toString('base64');
795+
return (str instanceof Buffer) ? str.toString('base64') : exports.createBuffer(str.toString(), 'utf8').toString('base64');
796796
};
797797

798798
exports.atob = function(str) {
799-
return exports.createBuffer(str, 'base64').toString('binary');
799+
return exports.createBuffer(str, 'base64').toString('utf8');
800800
};
801801

802802
/**

0 commit comments

Comments
 (0)