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

Re: Form reuse doesn't update content [PATCH]



On 2018-03-30 18:49, Katsumi Yamaoka wrote:
> In [emacs-w3m:12943]
> On Fri, 30 Mar 2018 04:13:29 -0400, Boruch Baum wrote:
> > I was using emacs-w3m to edit a wiki, which initially worked flawlessly.
> > However, when I attempted to edit the page a second time, the data in
> > the w3m form edit window buffer did not update its content. What I mean
> > is that it had the original text of the page prior to the first edit.

The attached patch seems to solve the problem, but I can't be certain
that it won't have some undesirable / unforeseen side-effect(s). What
seems to have been happening seems to have been an issue in the
w3m-cache rather than w3m-history or w3m-current-forms, in that if a
cached version of the url was found, it was used (we want that) even
though the url contained form textareas which may have been changed
since the cache entry was saved (obviously we don't want that).

The patch addresses this in a somewhat brute force manner by refusing to
use the cache if the url includes a "<textarea" tag.

Possible problems with this might be:

1] There may be other tags which should be tracked. A safer
   method would have been to search on "<form", but I thought it
   unlikely that in practice anyone would care about changed radio
   buttons or other form elements. I'm undecided about this, and would
   readily accept if someone wants to change the search string to
   "<form" instead of "<textarea".

2] If the html source code includes a comment with the string
   "<textarea", this solution will never use the cached version, and
   will cause unnecessary downloads.

For your consideration,


-- 
hkp://keys.gnupg.net
CA45 09B5 5351 7C11 A9D1  7286 0036 9E45 1595 8BC0
Index: w3m.el
===================================================================
RCS file: /storage/cvsroot/emacs-w3m/w3m.el,v
retrieving revision 1.1706
diff -u -r1.1706 w3m.el
--- w3m.el	27 Feb 2018 06:23:35 -0000	1.1706
+++ w3m.el	3 Apr 2018 09:07:54 -0000
@@ -4913,13 +5030,17 @@
 	      (setq end (next-single-property-change
 			 (1+ beg) 'w3m-cache (current-buffer) (point-max)))
 	    ;; It wasn't in the cache after all.
-	    (setq w3m-cache-articles (delq ident w3m-cache-articles))))
+	    (setq w3m-cache-articles (delq ident w3m-cache-articles)))
+          (unless (and (goto-char beg)
+                       (search-forward "<textarea"end t))
+            (setq beg nil)))
 	(and beg
 	     end
 	     (with-current-buffer (or buffer (current-buffer))
 	       (let ((inhibit-read-only t))
 		 (insert-buffer-substring w3m-cache-buffer beg end))
-	       t))))))
+ 	       t))))))
+

 ;; FIXME: we need to check whether contents were updated in remote servers.
 (defun w3m-cache-available-p (url)