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

Boruch Baum <[email protected]>
Newsgroups gmane.emacs.w3m
Message-ID <emacs-w3m/emacs-w3m/issues/[email protected]>
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-url`the 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

``` emacs-lisp
(when (and (stringp url) (not (w3m-interactive-p)))
  (setq url (w3m-canonicalize-url url)))
```
with

``` emacs-lisp
(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)))
      engine-info)
  (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 or view it on GitHub:
https://github.com/emacs-w3m/emacs-w3m/issues/52
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.