Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Following
Here is the fix for the piratebay search engine. A gist of the code is available here for testing.
Recalling the problem:
API apibay.org returns weird JSON that causes the piratebay search engine to crash when handling its response. If some search results contain
"
(quotation marks) characters, the server escapes them by replacing"
with"
HTML entities in order to still provide a syntactically valid JSON response. While this is not incorrect, it would be best if apibay.org returned properly escaped quotes, i.e. using backslashes.When handling the response data, functions
retrieve_url
andhtmlentitydecode
blindly unescape all entities thereby corrupting previously valid JSON. As a consequence,json.loads
crashes. For example:becomes
Solution proposed
We no logner use the
retrieve_url
function -- instead, I created a dedicatedretrieve_url
function (which is almost a copy-paste of the orignal) that fixes the problem by manually escaping quotes before escaping the rest of the data.