fix(dom) bug in Firefox with Imagus extension enabled: change getCurrentName to read from data-name instead of title (#313)

Separated out name generation/parsing logic.
Added test case.
This commit is contained in:
Jacob Henry 2021-01-18 13:42:31 -05:00 committed by coderaiser
parent b6f30d1ccb
commit c057b950c8
9 changed files with 122 additions and 25 deletions

20
common/base64.js Normal file
View file

@ -0,0 +1,20 @@
'use strict';
module.exports.btoa = (str) => {
if (typeof btoa === 'function')
return btoa(str);
return Buffer
.from(str)
.toString('base64');
};
module.exports.atob = (str) => {
if (typeof atob === 'function')
return atob(str);
return Buffer
.from(str, 'base64')
.toString('binary');
};

55
common/base64.spec.js Normal file
View file

@ -0,0 +1,55 @@
'use strict';
const test = require('supertape');
const stub = require('@cloudcmd/stub');
const {btoa, atob} = require('./base64');
test('btoa: browser', (t) => {
const btoaOriginal = global.btoa;
const str = 'hello';
global.btoa = stub();
btoa(str);
t.calledWith(global.btoa, [str], 'should call global.btoa');
t.end();
global.btoa = btoaOriginal;
});
test('btoa: node', (t) => {
const str = 'hello';
const expected = 'aGVsbG8=';
const result = btoa(str);
t.equal(result, expected, 'should encode base64');
t.end();
});
test('atob: browser', (t) => {
const atobOriginal = global.atob;
const str = 'hello';
global.atob = stub();
atob(str);
t.calledWith(global.atob, [str], 'should call global.btoa');
t.end();
global.atob = atobOriginal;
});
test('atob: node', (t) => {
const str = 'aGVsbG8=';
const expected = 'hello';
const result = atob(str);
t.equal(result, expected, 'should encode base64');
t.end();
});

View file

@ -1,11 +0,0 @@
'use strict';
module.exports = (str) => {
if (typeof btoa === 'function')
return btoa(str);
return Buffer
.from(str)
.toString('base64');
};

View file

@ -4,7 +4,7 @@ const rendy = require('rendy');
const currify = require('currify');
const store = require('fullstore');
const {encode} = require('./entity');
const btoa = require('./btoa');
const {btoa} = require('./base64');
const getHeaderField = currify(_getHeaderField);
@ -177,7 +177,7 @@ module.exports.buildFromJSON = (params) => {
name: '..',
});
const dataName = 'data-name="js-file-.." ';
const dataName = getDataName('..');
const attribute = 'draggable="true" ' + dataName;
/* Сохраняем путь к каталогу верхнего уровня*/

View file

@ -5,14 +5,50 @@ const {readFileSync} = require('fs');
const test = require('supertape');
const montag = require('montag');
const cheerio = require('cheerio');
const {_getSize, getPathLink} = require('./cloudfunc');
const {
_getSize,
getPathLink,
buildFromJSON,
} = require('./cloudfunc');
const templatePath = join(__dirname, '../tmpl/fs');
const template = {
pathLink: readFileSync(`${templatePath}/pathLink.hbs`, 'utf8'),
path: readFileSync(`${templatePath}/path.hbs`, 'utf8'),
file: readFileSync(`${templatePath}/file.hbs`, 'utf8'),
link: readFileSync(`${templatePath}/link.hbs`, 'utf8'),
};
test('cloudfunc: buildFromJSON: ..', (t) => {
const data = {
path: '/media/',
files: [{
date: '30.08.2016',
mode: 'rwx rwx rwx',
name: 'floppy',
owner: 'root',
size: '7b',
type: 'directory-link',
}],
};
const html = buildFromJSON({
prefix: '',
template,
data,
});
const $ = cheerio.load(html);
const el = $('[data-name="js-file-Li4="]');
const result = el.find('[data-name="js-name"]').text();
const expected = '..';
t.equal(result, expected);
t.end();
});
test('cloudfunc: getPathLink: /', (t) => {
const {pathLink} = template;
const result = getPathLink('/', '', pathLink);