all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#36520: Form submition in eww doesn't work if file field is left empty
@ 2019-07-06 10:39 Ivaylo Ilionov
  2019-07-07 16:38 ` Basil L. Contovounesios
  0 siblings, 1 reply; 4+ messages in thread
From: Ivaylo Ilionov @ 2019-07-06 10:39 UTC (permalink / raw)
  To: 36520

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

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

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

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

Details about my emacs:

In GNU Emacs 27.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 2.24.32)
 of 2019-07-05 built on debian
Repository revision: f24d47359d9b6621215f20795d585c5024d91783
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12004000
System Description: Debian GNU/Linux 10 (buster)


[-- Attachment #2: Type: text/html, Size: 2431 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#36520: Form submition in eww doesn't work if file field is left empty
  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
  2019-07-07 20:57   ` Ivaylo Ilionov
  2019-09-14 14:55   ` Lars Ingebrigtsen
  0 siblings, 2 replies; 4+ messages in thread
From: Basil L. Contovounesios @ 2019-07-07 16:38 UTC (permalink / raw)
  To: Ivaylo Ilionov; +Cc: 36520

[-- 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

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* bug#36520: Form submition in eww doesn't work if file field is left empty
  2019-07-07 16:38 ` Basil L. Contovounesios
@ 2019-07-07 20:57   ` Ivaylo Ilionov
  2019-09-14 14:55   ` Lars Ingebrigtsen
  1 sibling, 0 replies; 4+ messages in thread
From: Ivaylo Ilionov @ 2019-07-07 20:57 UTC (permalink / raw)
  To: Basil L. Contovounesios; +Cc: 36520@debbugs.gnu.org

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

Basil L. Contovounesios <contovob@tcd.ie> writes:
> I wonder if the file not being initialised is a symptom of a problem
elsewhere?  An example might shed more light on this.

It's quite possible that my suggestion is a low quality patch or just
hides the real problem. I don't have a good undertanding of the
code for eww.

I've first encountered the problem in Redmine version 4.0.3.
The action which triggered the error was that for changing status
of an issue from "New" to "In Progress". The form contains
many things including the option to upload files for the issue
when changing statuses.

Here's a sample web form which demonstrates the problem:

<html> <body>
    <form action="/non-existent.cgi" method="post">
      Short comment: <input name='comment' type='text' /><br/>
      Optional file: <input name='file' type='file' /><br/>
      <input type='submit'/><br/>
      <input type='reset'/>
    </form>
</body> </html>

If a file hasn't been chosen the submition doesn't seem to work.
If a file is chosen i get a proper error from the server ("not found").

________________________________
From: Basil L. Contovounesios <contovob@tcd.ie>
Sent: Sunday, July 7, 2019 19:38
To: Ivaylo Ilionov
Cc: 36520@debbugs.gnu.org
Subject: Re: bug#36520: Form submition in eww doesn't work if file field is left empty

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:


[-- Attachment #2: Type: text/html, Size: 6209 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#36520: Form submition in eww doesn't work if file field is left empty
  2019-07-07 16:38 ` Basil L. Contovounesios
  2019-07-07 20:57   ` Ivaylo Ilionov
@ 2019-09-14 14:55   ` Lars Ingebrigtsen
  1 sibling, 0 replies; 4+ messages in thread
From: Lars Ingebrigtsen @ 2019-09-14 14:55 UTC (permalink / raw)
  To: Basil L. Contovounesios; +Cc: 36520, Ivaylo Ilionov

"Basil L. Contovounesios" <contovob@tcd.ie> writes:

> 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.

I did some testing, and it seemed to work fine for me, so I've applied
it to the trunk and pushed it.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-09-14 14:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2019-07-07 20:57   ` Ivaylo Ilionov
2019-09-14 14:55   ` Lars Ingebrigtsen

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.