From c3e87a2097441a022a142cb81b0b23009028245b Mon Sep 17 00:00:00 2001 From: Andreas Gerler Date: Tue, 22 Jan 2019 15:25:28 +0100 Subject: [PATCH] Update simple-httpd. Signed-off-by: Andreas Gerler --- .../simple-httpd-pkg.el | 2 - .../simple-httpd-autoloads.el | 0 .../simple-httpd-pkg.el | 2 + .../simple-httpd.el | 41 +++++++++++++++++-- 4 files changed, 40 insertions(+), 5 deletions(-) delete mode 100644 elpa/simple-httpd-20180528.1603/simple-httpd-pkg.el rename elpa/{simple-httpd-20180528.1603 => simple-httpd-20190110.1505}/simple-httpd-autoloads.el (100%) create mode 100644 elpa/simple-httpd-20190110.1505/simple-httpd-pkg.el rename elpa/{simple-httpd-20180528.1603 => simple-httpd-20190110.1505}/simple-httpd.el (96%) diff --git a/elpa/simple-httpd-20180528.1603/simple-httpd-pkg.el b/elpa/simple-httpd-20180528.1603/simple-httpd-pkg.el deleted file mode 100644 index 88c9c1fe..00000000 --- a/elpa/simple-httpd-20180528.1603/simple-httpd-pkg.el +++ /dev/null @@ -1,2 +0,0 @@ -;;; -*- no-byte-compile: t -*- -(define-package "simple-httpd" "20180528.1603" "pure elisp HTTP server" '((cl-lib "0.3")) :commit "49721d5b791bee0fc25b1fdd69696371d546093a" :authors '(("Christopher Wellons" . "wellons@nullprogram.com")) :maintainer '("Christopher Wellons" . "wellons@nullprogram.com") :url "https://github.com/skeeto/emacs-http-server") diff --git a/elpa/simple-httpd-20180528.1603/simple-httpd-autoloads.el b/elpa/simple-httpd-20190110.1505/simple-httpd-autoloads.el similarity index 100% rename from elpa/simple-httpd-20180528.1603/simple-httpd-autoloads.el rename to elpa/simple-httpd-20190110.1505/simple-httpd-autoloads.el diff --git a/elpa/simple-httpd-20190110.1505/simple-httpd-pkg.el b/elpa/simple-httpd-20190110.1505/simple-httpd-pkg.el new file mode 100644 index 00000000..703007b2 --- /dev/null +++ b/elpa/simple-httpd-20190110.1505/simple-httpd-pkg.el @@ -0,0 +1,2 @@ +;;; -*- no-byte-compile: t -*- +(define-package "simple-httpd" "20190110.1505" "pure elisp HTTP server" '((cl-lib "0.3")) :commit "08535d0fad6a32fdc03d725ec74e10a754bb9c7a" :authors '(("Christopher Wellons" . "wellons@nullprogram.com")) :maintainer '("Christopher Wellons" . "wellons@nullprogram.com") :url "https://github.com/skeeto/emacs-http-server") diff --git a/elpa/simple-httpd-20180528.1603/simple-httpd.el b/elpa/simple-httpd-20190110.1505/simple-httpd.el similarity index 96% rename from elpa/simple-httpd-20180528.1603/simple-httpd.el rename to elpa/simple-httpd-20190110.1505/simple-httpd.el index 07e18950..ebf3ca09 100644 --- a/elpa/simple-httpd-20180528.1603/simple-httpd.el +++ b/elpa/simple-httpd-20190110.1505/simple-httpd.el @@ -4,7 +4,7 @@ ;; Author: Christopher Wellons ;; URL: https://github.com/skeeto/emacs-http-server -;; Package-Version: 20180528.1603 +;; Package-Version: 20190110.1505 ;; Version: 1.5.1 ;; Package-Requires: ((cl-lib "0.3")) @@ -179,6 +179,11 @@ :group 'simple-httpd :type 'boolean) +(defcustom httpd-show-backtrace-when-error nil + "If true, show backtrace on error page." + :group 'simple-httpd + :type 'boolean) + (defcustom httpd-start-hook nil "Hook to run when the server has started." :group 'simple-httpd @@ -695,6 +700,23 @@ element is the fragment." (push (if p1 (httpd-parse-args (substring uri (1+ p1) p2))) retval) (push (substring uri 0 (or p1 p2)) retval))) +(defun httpd-escape-html-buffer () + "Escape current buffer contents to be safe for inserting into HTML." + (setf (point) (point-min)) + (while (search-forward-regexp "[<>&]" nil t) + (replace-match + (cl-case (aref (match-string 0) 0) + (?< "<") + (?> ">") + (?& "&"))))) + +(defun httpd-escape-html (string) + "Escape STRING so that it's safe to insert into an HTML document." + (with-temp-buffer + (insert string) + (httpd-escape-html-buffer) + (buffer-string))) + ;; Path handling (defun httpd-status (path) @@ -856,8 +878,21 @@ optionally inserting object INFO into page. If PROC is T use the (httpd-log `(error ,status ,info)) (with-temp-buffer (let ((html (or (cdr (assq status httpd-html)) "")) - (erro (url-insert-entities-in-string (format "error: %s" info)))) - (insert (format html (if info erro "")))) + (contents + (if (not info) + "" + (with-temp-buffer + (let ((standard-output (current-buffer))) + (insert "error: ") + (princ info) + (insert "\n") + (when httpd-show-backtrace-when-error + (insert "backtrace: ") + (princ (backtrace)) + (insert "\n")) + (httpd-escape-html-buffer) + (buffer-string)))))) + (insert (format html contents))) (httpd-send-header proc "text/html" status))) (defun httpd--error-safe (&rest args) -- 2.47.3