Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sanitize JSON-LD input before decoding #41

Merged
merged 4 commits into from
Nov 1, 2019
Merged

Conversation

rvanlaak
Copy link
Collaborator

@rvanlaak rvanlaak commented Oct 30, 2019

This PR relies on #38 getting merged, as commit e4e9a18 is the commit that fixes the bug

When the Json ends with a ; the json can not get decoded.

Example

WHO content ends with an ;. As result of that the NewsArticle can not get parsed.

https://www.who.int/news-room/detail/17-10-2019-7-million-people-receive-record-levels-of-lifesaving-tb-treatment-but-3-million-still-miss-out

How to test

Run while parsing above URL

Or test the following JSON snippet on https://jsonlint.com/#:

{"author":{"@type":"Organization","name":"World Health Organization: WHO","logo":{"@type":"ImageObject","url":"http://www.who.int/Images/SchemaOrg/schemaOrgLogo.jpg","width":250,"height":60}},"headline":"7 million people receive record levels of lifesaving TB treatment but 3 million still miss out","description":"<p>More people received life-saving treatment for tuberculosis (TB) in 2018 than ever before, largely due to improved detection and diagnosis. Globally, 7 million people were diagnosed and treated for TB - up from 6.4 million in 2017 &ndash; enabling the world to meet one of the milestones towards the United Nations political declaration targets on TB. </p> [...] <p>Brazil, China, the Russian Federation and Zimbabwe, which all have high TB burdens, achieved treatment coverage levels of more than 80 per cent.</p>","datePublished":"2019-10-17T22:01:00.0000000+00:00","image":"https://www.who.int/images/default-source/wpro/news/feature-stories/cambodia-tb-screening.jpg?sfvrsn=e7bbe3fb_20","publisher":{"@type":"Organization","name":"World Health Organization: WHO","logo":{"@type":"ImageObject","url":"http://www.who.int/Images/SchemaOrg/schemaOrgLogo.jpg","width":250,"height":60}},"dateModified":"2019-10-17T22:01:00.0000000+00:00","mainEntityOfPage":"https://www.who.int/news-room/detail/17-10-2019-7-million-people-receive-record-levels-of-lifesaving-tb-treatment-but-3-million-still-miss-out","@context":"http://schema.org","@type":"NewsArticle"};

How to fix

check if the last character is a ;, and strip that

@coveralls
Copy link

coveralls commented Oct 30, 2019

Coverage Status

Coverage increased (+0.0003%) to 99.555% when pulling e4e9a18 on rvanlaak:patch-1 into eb7d515 on jkphl:master.

@jkphl
Copy link
Owner

jkphl commented Nov 1, 2019

@rvanlaak Thanks!

@jkphl jkphl merged commit 1958213 into jkphl:master Nov 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants