From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: "Basil L. Contovounesios" Newsgroups: gmane.emacs.bugs 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 Message-ID: <87d0iler5r.fsf@tcd.ie> References: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="264328"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: 36520@debbugs.gnu.org To: Ivaylo Ilionov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Jul 07 18:39:22 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1hkAC9-0016do-M7 for geb-bug-gnu-emacs@m.gmane.org; Sun, 07 Jul 2019 18:39:21 +0200 Original-Received: from localhost ([::1]:36236 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hkAC8-0005Rr-GZ for geb-bug-gnu-emacs@m.gmane.org; Sun, 07 Jul 2019 12:39:20 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:41836) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hkABt-0005Qa-DF for bug-gnu-emacs@gnu.org; Sun, 07 Jul 2019 12:39:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hkABr-0002OP-R8 for bug-gnu-emacs@gnu.org; Sun, 07 Jul 2019 12:39:05 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:48529) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hkABq-0002L7-B5 for bug-gnu-emacs@gnu.org; Sun, 07 Jul 2019 12:39:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hkABq-0005KX-2o for bug-gnu-emacs@gnu.org; Sun, 07 Jul 2019 12:39:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: "Basil L. Contovounesios" Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 07 Jul 2019 16:39:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 36520 X-GNU-PR-Package: emacs Original-Received: via spool by 36520-submit@debbugs.gnu.org id=B36520.156251751920457 (code B ref 36520); Sun, 07 Jul 2019 16:39:02 +0000 Original-Received: (at 36520) by debbugs.gnu.org; 7 Jul 2019 16:38:39 +0000 Original-Received: from localhost ([127.0.0.1]:57350 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hkABT-0005Jo-Gs for submit@debbugs.gnu.org; Sun, 07 Jul 2019 12:38:39 -0400 Original-Received: from mail-ed1-f68.google.com ([209.85.208.68]:33642) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hkABQ-0005JP-Ol for 36520@debbugs.gnu.org; Sun, 07 Jul 2019 12:38:38 -0400 Original-Received: by mail-ed1-f68.google.com with SMTP id i11so12399736edq.0 for <36520@debbugs.gnu.org>; Sun, 07 Jul 2019 09:38:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tcd-ie.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=5zdM2pQ3A7Y44TwVonC/ecBbg2q80rkPV+XVH+odyl4=; b=ZHeywVpRnt1PP62hRwB2YWgoFjJuBY3BOncyQSrexmIfttI4uj+o4zTIH2hOzOnQ8B a2g95qNlOxe4mU3xXgTEZNuwZOc6QIx83KpL1cnU2VIp2n0qi+LFUeJC86kS4RHnKy3h 4Bm3jcvhM4TKG8bJNsEScD9J7auZEH8WJNXqjHjaQS/mvIaVSjeWr6/0I+nGkEQqm6wD 2cEa2sNun7a8YTy95UcetBeku72HR/mESKxf3OoZ3bOMiyHxd3jzF9WS9Wc2teaRhD1Y cEfn8ZL0AQU5XdNNM4D6Hs/tFV51AaxUNaGN7tagyQUxqn2C4K+EjzOTAI7fdLam9chU zfdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=5zdM2pQ3A7Y44TwVonC/ecBbg2q80rkPV+XVH+odyl4=; b=k58uc1VjAE6U1G+6b/rr52mHKhfXCNarQW8+PhEIjhCH8ec2MSCnCWcUgbxjsO2PlG w9ZbIqbyQc8sfceWSCxni6udsozsgsb3it3XVQOFaMXhQydnhprE4Od3TL6R4E6ceegn qvH92T2bubEInlFmnG0guiRRFlXoAKiyb03G+ruqQOaUTeqM6F5lnxtP/F2AmwwFmluI WcvP5h4EyBhZ2yZ0bjs1IYyNjQqFONzc0maflI34sRhjidoWakIoQhGIiEVQgw+G/cOT PCII6BcciGXHmi2SgYb/m2PF1Qnf1TijYP0xMfa8i+5L4XpV+IqATYrABjnewTcr0SSc JWBA== X-Gm-Message-State: APjAAAXIbEvUMVagO+/BbeSiCSuxLfZnlkviWh+FXV2KC8I9OwEv3606 6ylqE8jDkUSRA5/tcTDJUn8w0Q== X-Google-Smtp-Source: APXvYqw68tpAsQR3Rrj2zFPpaVobeLuQNOgcQ/0MYcYjtFVDv4Zl2y+kSGyCipYrPvCgRElQiKsIyg== X-Received: by 2002:aa7:d909:: with SMTP id a9mr15682034edr.261.1562517510739; Sun, 07 Jul 2019 09:38:30 -0700 (PDT) Original-Received: from localhost ([2a02:8084:20e2:c380:92bd:1bfd:38fc:fae2]) by smtp.gmail.com with ESMTPSA id d4sm4690253edb.4.2019.07.07.09.38.29 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sun, 07 Jul 2019 09:38:29 -0700 (PDT) In-Reply-To: (Ivaylo Ilionov's message of "Sat, 6 Jul 2019 10:39:41 +0000") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:162290 Archived-At: --=-=-= Content-Type: text/plain tags 36520 + patch quit Ivaylo Ilionov 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: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Fix-fileless-eww-form-submission.patch >From 6c4fdcf2434391236d9ac1a891ba751e82831e37 Mon Sep 17 00:00:00 2001 From: "Basil L. Contovounesios" 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 --=-=-= Content-Type: text/plain 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 --=-=-=--