unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#15285: url-data not working for base64-encoded data
@ 2013-09-06  9:22 Klaus Straubinger
  2013-09-16 21:31 ` Glenn Morris
  0 siblings, 1 reply; 2+ messages in thread
From: Klaus Straubinger @ 2013-09-06  9:22 UTC (permalink / raw)
  To: 15285

In GNU Emacs 24.3.1 (i386-mingw-nt6.1.7601),
evaluating

    (require 'mm-decode)
    (require 'url)
    (mm-display-part
     (with-current-buffer
         (url-retrieve-synchronously
          "data:image/x-portable-bitmap;base64,UDQKMTQgMTAK//zgHJAkiESHhItEkCSgFMAM//w=")
       (mm-dissect-buffer t)))

should insert a letter image into the current buffer, but this does not work.

The cause is that in the function url-data (defined in url-misc.el)
the handling of the base64 parameter moves the match end and so the
starting "," character gets into the data, making them invalid.

Furthermore, instead of inserting the header "Content-Encoding" (that
should be used for encodings like "gzip") the code should insert the
header "Content-Transfer-Encoding" (the correct one for "8bit" or "base64").

-- 
Klaus Straubinger





^ permalink raw reply	[flat|nested] 2+ messages in thread

* bug#15285: url-data not working for base64-encoded data
  2013-09-06  9:22 bug#15285: url-data not working for base64-encoded data Klaus Straubinger
@ 2013-09-16 21:31 ` Glenn Morris
  0 siblings, 0 replies; 2+ messages in thread
From: Glenn Morris @ 2013-09-16 21:31 UTC (permalink / raw)
  To: 15285-done

Version: 24.4

Thanks for the clear report.
(I needed to add a "(require 'mm-view)" to the test-case).

I think this fixes it:

*** lisp/url/url-misc.el	2013-01-02 16:13:04 +0000
--- lisp/url/url-misc.el	2013-09-16 21:28:11 +0000
***************
*** 89,107 ****
      (save-excursion
        (if (not (string-match "\\([^,]*\\)?," desc))
  	  (error "Malformed data URL: %s" desc)
! 	(setq mediatype (match-string 1 desc))
  	(if (and mediatype (string-match ";base64\\'" mediatype))
  	    (setq mediatype (substring mediatype 0 (match-beginning 0))
  		  encoding "base64"))
  	(if (or (null mediatype)
  		(eq ?\; (aref mediatype 0)))
! 	  (setq mediatype (concat "text/plain" mediatype)))
! 	(setq data (url-unhex-string (substring desc (match-end 0)))))
        (set-buffer (generate-new-buffer " *url-data*"))
        (mm-disable-multibyte)
        (insert (format "Content-Length: %d\n" (length data))
  	      "Content-Type: " mediatype "\n"
! 	      "Content-Encoding: " encoding "\n"
  	      "\n")
        (if data (insert data))
        (current-buffer))))
--- 88,106 ----
      (save-excursion
        (if (not (string-match "\\([^,]*\\)?," desc))
  	  (error "Malformed data URL: %s" desc)
! 	(setq mediatype (match-string 1 desc)
! 	      data (url-unhex-string (substring desc (match-end 0))))
  	(if (and mediatype (string-match ";base64\\'" mediatype))
  	    (setq mediatype (substring mediatype 0 (match-beginning 0))
  		  encoding "base64"))
  	(if (or (null mediatype)
  		(eq ?\; (aref mediatype 0)))
! 	  (setq mediatype (concat "text/plain" mediatype))))
        (set-buffer (generate-new-buffer " *url-data*"))
        (mm-disable-multibyte)
        (insert (format "Content-Length: %d\n" (length data))
  	      "Content-Type: " mediatype "\n"
! 	      "Content-Transfer-Encoding: " encoding "\n"
  	      "\n")
        (if data (insert data))
        (current-buffer))))






^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-09-16 21:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-06  9:22 bug#15285: url-data not working for base64-encoded data Klaus Straubinger
2013-09-16 21:31 ` Glenn Morris

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).