From ae031928af3988367b9524ee979a80154fc0f632 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Thu, 22 Mar 2018 08:14:03 -0400 Subject: [PATCH] lang/org: fix attachments getting double-url-encoded when exported --- modules/lang/org/autoload/org-attach.el | 31 +++++++++++++------------ 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/modules/lang/org/autoload/org-attach.el b/modules/lang/org/autoload/org-attach.el index 149204975..ad74b56b9 100644 --- a/modules/lang/org/autoload/org-attach.el +++ b/modules/lang/org/autoload/org-attach.el @@ -83,21 +83,22 @@ the cursor." (unless (eq major-mode 'org-mode) (user-error "Not in an org buffer")) (require 'org-download) - (condition-case ex - (cond ((string-match-p "^data:image/png;base64," uri) - (org-download-dnd-base64 uri nil)) - ((image-type-from-file-name uri) - (org-download-image uri)) - (t - (let ((new-path (expand-file-name (org-download--fullname uri)))) - ;; Download the file - (if (string-match-p (concat "^" (regexp-opt '("http" "https" "nfs" "ftp" "file")) ":/") uri) - (url-copy-file uri new-path) - (copy-file uri new-path)) - ;; insert the link - (org-download-insert-link uri new-path)))) - (error - (user-error "Failed to attach file: %s" (error-message-string ex))))) + (let ((raw-uri (url-unhex-string uri))) + (condition-case ex + (cond ((string-match-p "^data:image/png;base64," uri) + (org-download-dnd-base64 uri nil)) + ((image-type-from-file-name raw-uri) + (org-download-image raw-uri)) + (t + (let ((new-path (expand-file-name (org-download--fullname raw-uri)))) + ;; Download the file + (if (string-match-p (concat "^" (regexp-opt '("http" "https" "nfs" "ftp" "file")) ":/") uri) + (url-copy-file raw-uri new-path) + (copy-file uri new-path)) + ;; insert the link + (org-download-insert-link raw-uri new-path)))) + (error + (user-error "Failed to attach file: %s" (error-message-string ex)))))) ;;;###autoload (defun +org-attach-download-dnd (uri action)