bug-gnu-emacs
[Top][All Lists]
Advanced

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

bug#36520: Form submition in eww doesn't work if file field is left empt


From: Basil L. Contovounesios
Subject: bug#36520: Form submition in eww doesn't work if file field is left empty
Date: Sun, 07 Jul 2019 17:38:24 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

tags 36520 + patch
quit

Ivaylo Ilionov <ivaylo.ilionov@outlook.com> writes:

> When submitting form with various fields including one optional
> field for file upload, if the file filed is left empty - the
> submition doesn't work.
>
> The error is: Wrong type argument: stringp, nil

Could you please give an example of such a form, for
reproduction/testing purposes?

> I've tracked the problem to the function 'eww-submit' which tries
> to open a file for upload (the file was never initialized by the
> html form).

I wonder if the file not being initialised is a symptom of a problem
elsewhere?  An example might shed more light on this.

> My fix is to check if the property is set in the file "eww.el.gz" after
> line 1435:
>
>> ((equal (plist-get input :type) "file")
>>  ;; FIX check if property :filename is not nil
>>  (when (not (null (plist-get input :filename)))

FWIW, this is equivalent to (when (plist-get input :filename) ...).

>>    (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)))

LGTM.  Here's a patch which achieves the same effect and additionally
cleans up this code a tiny bit:

>From 6c4fdcf2434391236d9ac1a891ba751e82831e37 Mon Sep 17 00:00:00 2001
From: "Basil L. Contovounesios" <contovob@tcd.ie>
Date: Sun, 7 Jul 2019 15:36:36 +0100
Subject: [PATCH] Fix fileless eww form submission

* lisp/net/eww.el (eww-submit): Ignore file inputs with no
associated file name (bug#36520).
---
 lisp/net/eww.el | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/lisp/net/eww.el b/lisp/net/eww.el
index 1125929c03..5acc645574 100644
--- a/lisp/net/eww.el
+++ b/lisp/net/eww.el
@@ -1426,15 +1426,15 @@ eww-submit
              (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
-- 
2.20.1

This is probably fine to push as-is, as it's just a defensive guard, but
I'd rather get confirmation from someone else or play around with an
example of the bug first.

Thanks,

-- 
Basil

reply via email to

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