Pass more tests

- Allow leading spaces in headers (since we were already accepting
leading spaces everywhere else in the armored text).
- Read ReadableStreams before passing them to a Worker
This commit is contained in:
Daniel Huigens
2018-05-16 21:33:22 +02:00
parent 05479e6e6b
commit 37014ecf30
11 changed files with 64 additions and 55 deletions

View File

@@ -207,7 +207,6 @@ function dearmor(input) {
const reEmptyLine = /^[ \f\r\t\u00a0\u2000-\u200a\u202f\u205f\u3000]*$/;
const reader = stream.getReader(input);
let lineIndex = 0;
let type;
const headers = [];
let lastHeaders = headers;
@@ -232,13 +231,13 @@ function dearmor(input) {
});
while (true) {
let line = await reader.readLine();
if (!line) break;
if (lineIndex++ === 0) {
// trim string
line = line.trim();
if (line === undefined) {
controller.error('Misformed armored text');
break;
}
// remove trailing whitespace at end of lines
line = line.replace(/[\t\r\n ]+$/g, '');
// remove leading whitespace for compat with older versions of OpenPGP.js
line = line.trim();
if (!type) {
if (reSplit.test(line)) {
type = getType(line);
@@ -257,7 +256,7 @@ function dearmor(input) {
} else if (!textDone && type === 2) {
if (!reSplit.test(line)) {
// Reverse dash-escaping for msg
text.push(line.replace(/^- /mg, ''));
text.push(line.replace(/^- /, ''));
} else {
text = text.join('\r\n');
textDone = true;