export const opening = '';
export const closing = '';
export const message = text => opening + text + closing;
export const valid = message('finite fixture');
export const deep = n => '' + ''.repeat(n - 1) +
''.repeat(n - 1) + '';
export const elements = n => '' + ''.repeat(n - 1) + '';
export const attributes = n => ' ` a${i}="x"`).join('') + '/>';
export function boundary() {
// 16 attributes / 1024 name+value UTF-16 units including xmlns.
let attrs = ' xmlns="jabber:client"';
let chars = 'xmlns'.length + 'jabber:client'.length;
for (let i = 0; i < 15; i++) {
const name = `a${i}`;
const value = 'v'.repeat(i === 14 ? 1024 - chars - name.length : 60);
attrs += ` ${name}="${value}"`;
chars += name.length + value.length;
}
// Root + body + chain of 7 + 23 siblings = 32 elements; depth 8.
const before = ``;
const after = '' + ''.repeat(7) + ''.repeat(7) + ''.repeat(23) + '';
return {xml: before + 'z'.repeat(4096 - before.length - after.length) + after,
body: 'z'.repeat(4096 - before.length - after.length)};
}
export const invalid = [
['large stock body', message('b'.repeat(1048576)), 'bytes'],
['deep stock XML', deep(257), 'depth'],
['unfinished opening', opening, 'invalid-xml'],
['unfinished attribute', '', 'invalid-xml'],
['depth over', deep(9), 'depth'],
['elements over', elements(33), 'elements'],
['attributes over', attributes(17), 'attributes'],
['attribute value over', ``, 'attribute-value'],
['attribute chars over', ' `a${i}="${'x'.repeat(256)}"`).join(' ') + '/>', 'attribute-chars'],
['oversized name', `<${'x'.repeat(129)}/>`, 'name'],
['oversized attribute name', ``, 'name'],
['oversized unfinished token', '<' + 'x'.repeat(4096), 'bytes'],
['UTF-8 bytes over with bounded units', message('🦉'.repeat(1100)), 'bytes'],
['binary buffer', new Uint8Array([60, 120, 47, 62]), 'text-required'],
['binary ArrayBuffer', new ArrayBuffer(4), 'text-required'],
['binary Blob', new Blob([valid]), 'text-required'],
['boxed string', new String(valid), 'text-required'],
['comment', '' + valid, 'restricted-xml'],
['DTD internal entity', ']>' + message('&x;'), 'restricted-xml'],
['external DTD', '' + valid, 'restricted-xml'],
['processing instruction', '' + valid, 'restricted-xml'],
['XML declaration', '' + valid, 'restricted-xml'],
['duplicate attribute', '', 'invalid-xml'],
['duplicate expanded attribute', '', 'invalid-xml'],
['unbound namespace', '', 'invalid-xml'],
['illegal namespace binding', '', 'invalid-xml'],
['unknown entity', message('&unknown;'), 'invalid-xml'],
['illegal control', message('\u0000'), 'invalid-xml'],
['unpaired surrogate', message('\ud800'), 'invalid-xml'],
['invalid char reference', message(''), 'invalid-xml'],
['unknown root', '', 'unknown-root']
];