emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master 7c449b8: Add more sanity checks to the last eww aft


From: Lars Ingebrigtsen
Subject: [Emacs-diffs] master 7c449b8: Add more sanity checks to the last eww after-change-function patch
Date: Thu, 27 Nov 2014 16:50:10 +0000

branch: master
commit 7c449b8f0dc926a12dcb6d3abbdbd6fe8decadc8
Author: Lars Magne Ingebrigtsen <address@hidden>
Date:   Thu Nov 27 17:50:05 2014 +0100

    Add more sanity checks to the last eww after-change-function patch
---
 lisp/net/eww.el |   96 ++++++++++++++++++++++++++++---------------------------
 1 files changed, 49 insertions(+), 47 deletions(-)

diff --git a/lisp/net/eww.el b/lisp/net/eww.el
index 63a6c0d..a082fe5 100644
--- a/lisp/net/eww.el
+++ b/lisp/net/eww.el
@@ -953,53 +953,55 @@ appears in a <link> or <a> tag."
 See URL `https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Input'.")
 
 (defun eww-process-text-input (beg end length)
-  (let* ((pos (cond
-              ((get-text-property (1- end) 'eww-form)
-               (1- end))
-              ((get-text-property (1+ end) 'eww-form)
-               (1+ end))))
-        (form (get-text-property pos 'eww-form))
-        (properties (text-properties-at pos))
-        (inhibit-read-only t)
-        (type (plist-get form :type)))
-    (when (and form
-              (member type eww-text-input-types))
-      (cond
-       ((zerop length)
-       ;; Delete some space at the end.
-       (save-excursion
-         (goto-char
-          (if (equal type "textarea")
-              (1- (line-end-position))
-            (eww-end-of-field)))
-         (let ((new (- end beg)))
-           (while (and (> new 0)
-                       (eql (following-char) ? ))
-             (delete-region (point) (1+ (point)))
-             (setq new (1- new))))
-         (set-text-properties beg end properties)))
-       ((> length 0)
-       ;; Add padding.
-       (save-excursion
-         (goto-char (1- end))
-         (goto-char
-          (if (equal type "textarea")
-              (1- (line-end-position))
-            (1+ (eww-end-of-field))))
-         (let ((start (point)))
-           (insert (make-string length ? ))
-           (set-text-properties start (point) properties)))))
-      (let ((value (buffer-substring-no-properties
-                   (eww-beginning-of-field)
-                   (eww-end-of-field))))
-       (when (string-match " +\\'" value)
-         (setq value (substring value 0 (match-beginning 0))))
-       (plist-put form :value value)
-       (when (equal type "password")
-         ;; Display passwords as asterisks.
-         (let ((start (eww-beginning-of-field)))
-           (put-text-property start (+ start (length value))
-                              'display (make-string (length value) ?*))))))))
+  (when-let (pos (and (< (1+ end) (point-max))
+                     (> (1- end) (point-min))
+                     (cond
+                      ((get-text-property (1- end) 'eww-form)
+                       (1- end))
+                      ((get-text-property (1+ end) 'eww-form)
+                       (1+ end)))))
+    (let* ((form (get-text-property pos 'eww-form))
+          (properties (text-properties-at pos))
+          (inhibit-read-only t)
+          (type (plist-get form :type)))
+      (when (and form
+                (member type eww-text-input-types))
+       (cond
+        ((zerop length)
+         ;; Delete some space at the end.
+         (save-excursion
+           (goto-char
+            (if (equal type "textarea")
+                (1- (line-end-position))
+              (eww-end-of-field)))
+           (let ((new (- end beg)))
+             (while (and (> new 0)
+                         (eql (following-char) ? ))
+               (delete-region (point) (1+ (point)))
+               (setq new (1- new))))
+           (set-text-properties beg end properties)))
+        ((> length 0)
+         ;; Add padding.
+         (save-excursion
+           (goto-char (1- end))
+           (goto-char
+            (if (equal type "textarea")
+                (1- (line-end-position))
+              (1+ (eww-end-of-field))))
+           (let ((start (point)))
+             (insert (make-string length ? ))
+             (set-text-properties start (point) properties)))))
+       (let ((value (buffer-substring-no-properties
+                     (eww-beginning-of-field)
+                     (eww-end-of-field))))
+         (when (string-match " +\\'" value)
+           (setq value (substring value 0 (match-beginning 0))))
+         (plist-put form :value value)
+         (when (equal type "password")
+           ;; Display passwords as asterisks.
+           (let ((start (eww-beginning-of-field)))
+             (put-text-property start (+ start (length value))
+                                'display (make-string (length value) 
?*)))))))))
 
 (defun eww-tag-textarea (dom)
   (let ((start (point))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]