unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: "Basil L. Contovounesios" <contovob@tcd.ie>
To: Ivaylo Ilionov <ivaylo.ilionov@outlook.com>
Cc: 36520@debbugs.gnu.org
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	[thread overview]
Message-ID: <87d0iler5r.fsf@tcd.ie> (raw)
In-Reply-To: <VE1PR08MB513653BD4614A51CADF8E27C82F40@VE1PR08MB5136.eurprd08.prod.outlook.com> (Ivaylo Ilionov's message of "Sat, 6 Jul 2019 10:39:41 +0000")

[-- Attachment #1: Type: text/plain, Size: 1362 bytes --]

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:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fix-fileless-eww-form-submission.patch --]
[-- Type: text/x-diff, Size: 1592 bytes --]

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


[-- Attachment #3: Type: text/plain, Size: 189 bytes --]


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	other threads:[~2019-07-07 16:38 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-06 10:39 bug#36520: Form submition in eww doesn't work if file field is left empty Ivaylo Ilionov
2019-07-07 16:38 ` Basil L. Contovounesios [this message]
2019-07-07 20:57   ` Ivaylo Ilionov
2019-09-14 14:55   ` Lars Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87d0iler5r.fsf@tcd.ie \
    --to=contovob@tcd.ie \
    --cc=36520@debbugs.gnu.org \
    --cc=ivaylo.ilionov@outlook.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).