always remove trailing whitespace from lines when canonicalizing

This commit is contained in:
Sanjana Rajan 2018-04-17 08:41:52 -07:00
parent d785df3325
commit c28f7ad4d7
2 changed files with 2 additions and 2 deletions

View File

@ -43,7 +43,7 @@ export function CleartextMessage(text, signature) {
return new CleartextMessage(text, signature);
}
// normalize EOL to canonical form <CR><LF>
this.text = text.replace(/\r/g, '').replace(/[\t ]+\n/g, "\n").replace(/\n/g, "\r\n");
this.text = text.replace(/\r\n/g, "\n").replace(/\r/g, "\n").replace(/[ \t]+\n/g, "\n").replace(/\n/g, "\r\n");
if (signature && !(signature instanceof Signature)) {
throw new Error('Invalid signature input');
}

View File

@ -48,7 +48,7 @@ function Literal(date=new Date()) {
*/
Literal.prototype.setText = function(text) {
// normalize EOL to \r\n
text = text.replace(/\r\n/g, '\n').replace(/\r/g, '\n').replace(/\n/g, '\r\n');
text = text.replace(/\r\n/g, "\n").replace(/\r/g, "\n").replace(/[ \t]+\n/g, "\n").replace(/\n/g, "\r\n");
this.format = 'utf8';
// encode UTF8
this.data = util.str_to_Uint8Array(util.encode_utf8(text));