more robust handling of pagination Link headers
during a cursory investigation for #163 I found that the code handling Link headers would not handle non-numeric post IDs like pleroma's flakeIDs correctly IDs starting with a number would be truncated to the first non-digit, and IDs not starting with a number would throw. Thankfully, all flakeIDs generated so far start with 9. Maybe 8 for the earliest ones, I'm not sure. Either way, so far it would only have misbehaved when using the pagination functions or accessing the _pagination_prev and _pagination_next attributes directly
This commit is contained in:
pare
8b86269787
commit
ad96297a06
S'han modificat 1 arxius amb 12 adicions i 4 eliminacions
|
@ -2272,13 +2272,17 @@ class Mastodon:
|
|||
if url['rel'] == 'next':
|
||||
# Be paranoid and extract max_id specifically
|
||||
next_url = url['url']
|
||||
matchgroups = re.search(r"max_id=([0-9]*)", next_url)
|
||||
matchgroups = re.search(r"max_id=([^&]+)", next_url)
|
||||
|
||||
if matchgroups:
|
||||
next_params = copy.deepcopy(params)
|
||||
next_params['_pagination_method'] = method
|
||||
next_params['_pagination_endpoint'] = endpoint
|
||||
next_params['max_id'] = int(matchgroups.group(1))
|
||||
max_id = matchgroups.group(1)
|
||||
if max_id.is_digit():
|
||||
next_params['max_id'] = int(max_id)
|
||||
else:
|
||||
next_params['max_id'] = max_id
|
||||
if "since_id" in next_params:
|
||||
del next_params['since_id']
|
||||
response[-1]._pagination_next = next_params
|
||||
|
@ -2286,13 +2290,17 @@ class Mastodon:
|
|||
if url['rel'] == 'prev':
|
||||
# Be paranoid and extract since_id specifically
|
||||
prev_url = url['url']
|
||||
matchgroups = re.search(r"since_id=([0-9]*)", prev_url)
|
||||
matchgroups = re.search(r"since_id=([^&]+)", prev_url)
|
||||
|
||||
if matchgroups:
|
||||
prev_params = copy.deepcopy(params)
|
||||
prev_params['_pagination_method'] = method
|
||||
prev_params['_pagination_endpoint'] = endpoint
|
||||
prev_params['since_id'] = int(matchgroups.group(1))
|
||||
since_id = matchgroups.group(1)
|
||||
if since_id.is_digit():
|
||||
prev_params['since_id'] = int(since_id)
|
||||
else:
|
||||
prev_params['since_id'] = since_id
|
||||
if "max_id" in prev_params:
|
||||
del prev_params['max_id']
|
||||
response[0]._pagination_prev = prev_params
|
||||
|
|
Loading…
Referencia en una nova incidència