WordPress.org

Ready to get started?Download WordPress

Forums

Fedmich's Facebook Open Graph Meta
[resolved] Links to YouTube videos causing trash output (3 posts)

  1. nkinkade
    Member
    Posted 1 year ago #

    Plugin version: 1.15.4

    We were noticing that when we included links to YouTube videos in posts that a bunch of garbage was showing up in the header of the site where this plugin inserts its <meta/> tags. I tracked it down to what appears to have been an overly greedy regex. For example, when adding a link like this to a post:

    Pepsi MAX & Jeff Gordon

    The regex that was supposed to just be grabbing the video ID was instead grabbing "Q5mHPo2yDG8">Pepsi MAX & Jeff Gordon". The following patch seems to fix this:

    http://natha.nkinka.de/misc/facebook-and-digg-thumbnail-generator.php.patch

    http://wordpress.org/extend/plugins/facebook-and-digg-thumbnail-generator/

  2. fedmich
    Member
    Plugin Author

    Posted 1 year ago #

    Hello nkinkade,
    Thank you for reporting that. I appreciate you wanting to help and even sending patch of your codes.

    rather than doing this ([a-zA-Z0-9]+)@i
    you could do this ([a-z0-9]+)@i
    because i, (...)@i here means ignore case

    but still your code will not match this youtube link
    http://www.youtube.com/watch?v=M7lc1UVf-VE

    because it has "hyphen", sometimes videoId has hyphens and other non-alphanumeric characters.

    I'm running unit tests and a bunch of html code combinations and I think they all still work fine.
    Could you send me the actual HTML Codes in your post that you encountered this?

    Thanks mate

  3. nkinkade
    Member
    Posted 1 year ago #

    Thanks for the quick reply. When this URL is in $pcontent:

    http://www.youtube.com/watch?v=Q5mHPo2yDG8

    The output of your plugin is:

    http://natha.nkinka.de/misc/fedmich_facebook_open_graph_meta.html

    It's because the (.*) at the end of the regex on line 101 is greedily matching all the way to the end of the <a/> element, and so is the (.*) on line 107.

    I suppose you could fix this by changing the regex on line 107 to (.*?), but is there a specific the whole conditional block between lines 106-111 exists? It seems to be that you could eliminate everything between lines 100-111 by just changing the regex on line 96 to more thoroughly isolate the video ID. I don't know what characters can possibly show up in a YouTube video ID, but I would imagine that it certainly can't include a quote character, so it would seem that changing the regex on 95 to the following would suffice to eliminate lines 100-111:

    '@(www\.|)youtube.com/watch\?v=(.*?)"@i'

    Thanks!

    Nathan

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.