jarun / ddgr

:duck: DuckDuckGo from the terminal

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

bang query string not quoted

benhormann opened this issue · comments

cmd:
BROWSER=echo ddgr --np --show-browser-logs '!? tom & jerry'
or:
BROWSER=echo ddgr --show-browser-logs
!? tom & jerry

actual:
https://duckduckgo.com/?q=!? tom & jerry

expected:
https://duckduckgo.com/?q=%21%3F+tom+%26+jerry
or, also legal:
https://duckduckgo.com/?q=!%3F+tom+%26+jerry


Updating url.full() works, is this sufficient?:

@@ -439,9 +439,9 @@ class DdgUrl:
         q = ''
         if self._keywords:
             if isinstance(self._keywords, list):
-                q += '+'.join(list(self._keywords))
+                q += '+'.join(map(urllib.parse.quote_plus, self._keywords))
             else:
-                q += self._keywords
+                q += urllib.parse.quote_plus(self._keywords)
 
         url = (self.scheme + ':') if self.scheme else ''
         url += '//' + self.netloc + '/?q=' + q
commented

Do examples 3, 4 and 8 help?

Also, for these kind of changes we need more testing. For example, are results for normal searches the same? Google takes tokens within quotes as occurring together and/or must present. Are those kind of side-effects creeping in?

I agree, it needs proper testing. I didn't find any reference to that method besides handling a bang.
Normal searching works fine with ?, &, and = characters.

Do examples 3, 4 and 8 help?

!, ? and & need escaped in most shells, but are OK in a string. In most shells ddgr '!? tom & jerry' and ddgr \!\?\ tom\ \&\ jerry are equivalent (though the latter won't work in PowerShell, for example). Typing the search, !? tom & jerry, at the ddgr prompt is the easiest way to avoid shell specific escaping.

commented

I didn't find any reference to that method

There is no documented method. Please use the same search strings with and without your change and see if the results are same. Also do it in debug mode so you can see the query string as well.

commented

Please raise the PR when you are done with testing.

commented

Closing this as there's no update on the PR.