From c28f7ad4d7400db47850df716de5701f54b0017f Mon Sep 17 00:00:00 2001
From: Sanjana Rajan <srajan1@stanford.edu>
Date: Tue, 17 Apr 2018 08:41:52 -0700
Subject: [PATCH] always remove trailing whitespace from lines when
 canonicalizing

---
 src/cleartext.js      | 2 +-
 src/packet/literal.js | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/cleartext.js b/src/cleartext.js
index a43823f6..60352fa4 100644
--- a/src/cleartext.js
+++ b/src/cleartext.js
@@ -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');
   }
diff --git a/src/packet/literal.js b/src/packet/literal.js
index 453dddf2..0a6f8bee 100644
--- a/src/packet/literal.js
+++ b/src/packet/literal.js
@@ -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));