Skip to content

Commit

Permalink
fix bug in search, query was not escaped properly
Browse files Browse the repository at this point in the history
  • Loading branch information
bstoilov committed Nov 19, 2019
1 parent 433c896 commit da55af9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion messages_example.py
Expand Up @@ -83,4 +83,4 @@ def send_message(username, message):
# pinterest.send_message(conversation_id=conversation_id, pin_id="(pin_id)", message="hey")


send_message(username='hknives', message='hi2')
send_message(username='username', message='Hi')
6 changes: 4 additions & 2 deletions py3pin/Pinterest.py
Expand Up @@ -368,16 +368,17 @@ def delete_invite(self, board_id, invited_user_id, also_block=False):
def search(self, scope, query, page_size=250):

next_bookmark = self.bookmark_manager.get_bookmark(primary='search', secondary=query)

if next_bookmark == '-end-':
return []

terms = query.split(' ')
query = "%20".join(terms)

This comment has been minimized.

Copy link
@uzairzia

uzairzia Nov 19, 2019

@bstoilov Just a kind note, this should be: query = " ".join(terms)

escaped_query = "%20".join(terms)

This comment has been minimized.

Copy link
@uzairzia

uzairzia Nov 19, 2019

@bstoilov I believe the problem still persists because of this line. It should be query = " ".join(terms)
:) Cheers.

This comment has been minimized.

Copy link
@bstoilov

bstoilov Nov 20, 2019

Author Owner

I don't have anymore issues on my side, I tried with all sorts of queries. Can you give me a search query that produces wrong results, so I can debug?

As for the string join, if we do it like that we change nothing:

terms = query.split(' ')
query = " ".join(terms)

If you don't escape the spaces in the source_url you will get bad request.

term_meta_arr = []
for t in terms:
term_meta_arr.append('term_meta[]=' + t)
term_arg = "%7Ctyped&".join(term_meta_arr)
source_url = '/search/{}/?q={}&rs=typed&{}%7Ctyped'.format(scope, query, term_arg)
source_url = '/search/{}/?q={}&rs=typed&{}%7Ctyped'.format(scope, escaped_query, term_arg)
options = {
"isPrefetch": False,
"auto_correction_disabled": False,
Expand All @@ -392,6 +393,7 @@ def search(self, scope, query, page_size=250):
resp = self.get(url=url).json()

bookmark = resp['resource']['options']['bookmarks'][0]

self.bookmark_manager.add_bookmark(primary='search', secondary=query, bookmark=bookmark)
return resp['resource_response']['data']['results']

Expand Down

0 comments on commit da55af9

Please sign in to comment.