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

fix(): Added support for CDATA escaped html fields on xml oembed #96

Closed
wants to merge 1 commit into from

Conversation

adrian-seijo
Copy link

While doing some tests with unfurl I stumble upon Soundcloud XML implementation which was only partially working.

Looking at their XML it seems that they are escaping their html node with CDATA which is not unreasonable to be fair:

<oembed>
  <version type="float">1.0</version>
  <type>rich</type>
  <provider-name>SoundCloud</provider-name>
  <provider-url>https://soundcloud.com</provider-url>
  <height type="integer">400</height>
  <width>100%</width>
  <title>Bugle 179 - Playas gon play by The Bugle</title>
  <description>This week - oh PIPA, Republican't candidates and Craptain Italia. Remember to #savethebugle at http://www.thebuglepodcast.com</description>
  <thumbnail-url>https://i1.sndcdn.com/artworks-000017079411-pgm0ii-t500x500.jpg</thumbnail-url>
  <html><![CDATA[<iframe width="100%" height="400" scrolling="no" frameborder="no" src="https://w.soundcloud.com/player/?visual=true&url=https%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F34019569&show_artwork=true"></iframe>]]></html>
  <author-name>The Bugle</author-name>
  <author-url>https://soundcloud.com/the-bugle</author-url>
</oembed>

Now unfurl use of htmlparser assumes that any content on the html block will show up as a new tag but that is not the case here, it will show up as text.

So what I have done is to naively check for the tagname while we read text and assume that if we have any text on an html tag it will be for something like this. In that scenario I have, again verynaively, escaped that &lt; and &gt; adn the CDATA and push that string into the content.html.

I have added a new test to cover this, including the example from soudlocud, and everything seems fine. There is certainly room for improvement, that sanitisation of the CDATA is not the best but it does the job for the type of content that we will usually get in that field.

@jacktuck
Copy link
Owner

Thanks for raising this. The purposed solution does worry me a bit. I have something that should (hopefully) be more robust and will raise separate PR for you to checkout.

@jacktuck
Copy link
Owner

see #98

@jacktuck jacktuck closed this Oct 23, 2022
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.

None yet

2 participants