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

[emacs-w3m/emacs-w3m] quick-search doesn't work when POST-DATA is required (#52)

This came to light when reviewing PR#51

Reproducible: From a w3m buffer type 'G ddg:namazu'. Instead of
returning a search results page, emacs-w3m returns a blank search
input page.

The basic problem seems to me to be that function w3m-input-url
itself calls function w3m-canonicalize-url instead of letting its
own callers decide whether to do so.

What is happening is that function w3m-goto-url calls function
w3m-input-url as part of its interactive spec, so at the very
beginning of the function w3m-goto-url, the URL arg has already been
'sanitizied'. However, in Jakub's case of using the quick search
feature for duckduckgo (ie. user inputs a url "ddg:foo"), the tail of
that url needs to parsed and placed in arg POST-DATA, because the
entry for "ddg:" in w3m-uri-replace-alist uses function
w3m-search-uri-replace and the duckduckgo entry in variable
w3m-search-engine-alist has a fourth argument - POST-DATA.

So, because of this quick-search feature, w3m-input-url in its
current form can not be used by w3m-goto-url. Function
w3m-goto-url looks to me to be used in ten separate places, so a
refactor would need to be careful.

The simple solution seems to be to remove from function
w3m-goto-urlthe call to function w3m-canonicalize-url, and have
each caller itself decide whether and when to do so.

In the case of function w3m-goto-url, what looks to me to be a
solution is to replace

(when (and (stringp url) (not (w3m-interactive-p)))
  (setq url (w3m-canonicalize-url url)))


(let* ((uri-replace ; based upon: `w3m-uri-replace'
        (catch 'found-replacement
          (dolist (elem w3m-uri-replace-alist)
            (when (string-match (car elem) url)
              (throw 'found-replacement  elem)))))
      (query (substring url (match-end 0)))
  (when (and uri-replace query
             (eq (nth 1 uri-replace) 'w3m-search-uri-replace))
    ; based upon `w3m-search-uri-replace'
    (setq engine-info (assoc (nth 2 uri-replace) w3m-search-engine-alist))
    (when (and engine-info (< 2 (length engine-info)))
      (setq post-data (w3m-search-escape-query-string query (nth 2 engine-info))))))
(setq url (w3m-canonicalize-url url)))

You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.