FIX: Ensure uploads are linked

FIX: Ensure uploads are linked

diff --git a/assets/javascripts/lib/protocol.js.es6 b/assets/javascripts/lib/protocol.js.es6
index 1700ed1..05b0737 100644
--- a/assets/javascripts/lib/protocol.js.es6
+++ b/assets/javascripts/lib/protocol.js.es6
@@ -140,7 +140,7 @@ export function encrypt(key, data, opts) {
   let extra = "";
 
   if (opts && opts.includeUploads) {
-    const uploads = data.raw.match(/upload:\/\/[A-Za-z0-9]{27,27}/g);
+    const uploads = data.raw.match(/upload:\/\/[A-Za-z0-9\.]+/g);
     if (uploads) {
       extra += "\n" + uploads.map(upload => `[](${upload})`).join();
     }
diff --git a/lib/post_extensions.rb b/lib/post_extensions.rb
index e5ee2f2..3655ccd 100644
--- a/lib/post_extensions.rb
+++ b/lib/post_extensions.rb
@@ -1,8 +1,12 @@
 # frozen_string_literal: true
 
 module PostExtensions
+  def ciphertext
+    raw.split("\n")[0] || ""
+  end
+
   def is_encrypted?
     !!(topic&.is_encrypted? &&
-       raw.match(/\A[A-Za-z0-9+\\\/=$]+(\n.*)?\Z/))
+       ciphertext.match(/\A[A-Za-z0-9+\/=$]+\Z/))
   end
 end
diff --git a/plugin.rb b/plugin.rb
index 0954a18..08f5550 100644
--- a/plugin.rb
+++ b/plugin.rb
@@ -176,19 +176,23 @@ after_initialize do
   #
 
   Plugin::Filter.register(:after_post_cook) do |post, cooked|
-    post.is_encrypted? ? "<p>#{I18n.t('js.encrypt.encrypted_post')}</p>" : cooked
+    if post.is_encrypted?
+      cooked.gsub!(post.ciphertext, I18n.t('js.encrypt.encrypted_post'))
+    else
+      cooked
+    end
   end
 
   on(:post_process_cooked) do |doc, post|
     if post&.is_encrypted?
-      doc.inner_html = "<p>#{I18n.t('js.encrypt.encrypted_post')}</p>"
+      doc.inner_html.gsub!(post.ciphertext, I18n.t('js.encrypt.encrypted_post'))
     end
   end
 
   # Notifications
   on(:reduce_excerpt) do |doc, options|
     if options[:post]&.is_encrypted?
-      doc.inner_html = "<p>#{I18n.t('js.encrypt.encrypted_post')}</p>"
+      doc.inner_html = "<p>#{I18n.t('js.encrypt.encrypted_post_email')}</p>"
     end
   end
 
diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb
index 979bf53..2ad66c7 100644
--- a/spec/models/post_spec.rb
+++ b/spec/models/post_spec.rb
@@ -7,6 +7,12 @@ describe Post do
   let(:encrypt_user) { Fabricate(:encrypt_user) }
   let(:encrypt_post) { Fabricate(:encrypt_post, user: encrypt_user) }
 
+  context '#ciphertext' do
+    it 'works' do
+      expect(encrypt_post.raw).to eq(encrypt_post.raw)
+    end
+  end
+
   context '#is_encrypted?' do
     it 'works' do
       expect(post.is_encrypted?).to eq(false)

GitHub sha: 74b59606

What is this testing?

Sorry, nothing. It should test if the ciphertext is correctly extracted. I followed up in dcc92a8d0e27d2b85997755d887a7ee843a34d98.

1 Like