diff options
Diffstat (limited to 'lisp/net/eww.el')
-rw-r--r-- | lisp/net/eww.el | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/lisp/net/eww.el b/lisp/net/eww.el index 77e6cec9b04..fb495a98582 100644 --- a/lisp/net/eww.el +++ b/lisp/net/eww.el @@ -326,6 +326,18 @@ the default EWW buffer." #'url-hexify-string (split-string url) "+")))))) url) +(defun eww--preprocess-html (start end) + "Translate all < characters that do not look like start of tags into <." + (save-excursion + (save-restriction + (narrow-to-region start end) + (goto-char start) + (let ((case-fold-search t)) + (while (re-search-forward "<[^0-9a-z!/]" nil t) + (goto-char (match-beginning 0)) + (delete-region (point) (1+ (point))) + (insert "<")))))) + ;;;###autoload (defalias 'browse-web 'eww) ;;;###autoload @@ -479,6 +491,7 @@ Currently this means either text/html or application/xhtml+xml." ;; Remove CRLF and replace NUL with � before parsing. (while (re-search-forward "\\(\r$\\)\\|\0" nil t) (replace-match (if (match-beginning 1) "" "�") t t))) + (eww--preprocess-html (point) (point-max)) (libxml-parse-html-region (point) (point-max)))))) (source (and (null document) (buffer-substring (point) (point-max))))) @@ -716,6 +729,7 @@ the like." (condition-case nil (decode-coding-region (point-min) (point-max) 'utf-8) (coding-system-error nil)) + (eww--preprocess-html (point-min) (point-max)) (libxml-parse-html-region (point-min) (point-max)))) (base (plist-get eww-data :url))) (eww-score-readability dom) @@ -1433,15 +1447,15 @@ See URL `https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Input'.") (push (cons name (plist-get input :value)) values))) ((equal (plist-get input :type) "file") - (push (cons "file" - (list (cons "filedata" - (with-temp-buffer - (insert-file-contents - (plist-get input :filename)) - (buffer-string))) - (cons "name" (plist-get input :name)) - (cons "filename" (plist-get input :filename)))) - values)) + (when-let ((file (plist-get input :filename))) + (push (list "file" + (cons "filedata" + (with-temp-buffer + (insert-file-contents file) + (buffer-string))) + (cons "name" name) + (cons "filename" file)) + values))) ((equal (plist-get input :type) "submit") ;; We want the values from buttons if we hit a button if ;; we hit enter on it, or if it's the first button after |