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

  1. nkinkade
    Posted 3 years 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:



  2. fedmich
    Plugin Author

    Posted 3 years 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

    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
    Posted 3 years ago #

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


    The output of your plugin is:


    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:




Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Fedmich's Facebook Open Graph Meta
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic


No tags yet.