MyBB Community Forums

Full Version: Warning in class_parser with video url
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Most of the video posts submitted on my forum are for content provided by YouTube. A post was made and started throwing this error and it was not evident which one was, but it was consistent.
<error>
	<dateline>1677553797</dateline>
	<datetime>2023-02-28 03:09:57 UTC -0500</datetime>
	<script>inc/class_parser.php</script>
	<line>1522</line>
	<type>2</type>
	<friendly_type>Warning</friendly_type>
	<message>Undefined array key 1</message>
	<back_trace>#0  errorHandler->error() called at [/inc/class_error.php:153]
#1  errorHandler->error_callback() called at [/inc/class_parser.php:1522]
#2  postParser->mycode_parse_video() called at [/inc/class_parser.php:1660]
#3  postParser->mycode_parse_video_callback() called at [[PHP]: ]
#4  preg_replace_callback() called at [/inc/class_parser.php:513]
#5  postParser->parse_mycode() called at [/inc/class_parser.php:228]
#6  postParser->parse_message() called at [/inc/functions_post.php:830]
#7  build_postbit() called at [/showthread.php:1119]
</back_trace>
</error>

Finally narrowed it down by inserting debug statements to catch all parsed video urls and matching the timestamp and pid. Showpost pid and post pid were used to differentiate the source, whether linear or threaded. In the end that made no difference because it was the url throwing the error.

timestamp: 2023-02-28 03:09:57 UTC -0500.
$url: https://www.youtube.com/watch?v=Ryc8gGfnL5M&ab_channel=EmersonLake%26Palmer-Topic
showpost pid: -1
post pid: 586697
key-value pairs of $decoded_url: 'https://www.youtube.com/watch?v=Ryc8gGfnL5M&ab_channel=EmersonLake&Palmer-Topic'.
key-value pairs of $parsed_url: array (   'scheme' => 'https',   'host' => 'www.youtube.com',   'path' => '/watch',   'query' => 'v=Ryc8gGfnL5M&ab_channel=EmersonLake&Palmer-Topic', ).
$input: Ryc8gGfnL5M  |  EmersonLake  |  .
$path:   |  watch.
$id: Ryc8gGfnL5M

The warning occurs when $query element is parsed into list(key,value). Original line in code is 1510, current code line shown here at 1522 is offset by my added debug code. This line is throwing the error.
			list($key, $value) = explode("=", $query);

The problem is in the URL. YouTube properly encoded the channel name EmersonLake%26Palmer to maintain the ampersand in the url as the query delimiter. However, the urldecode() in this line 1485
		$parsed_url = @parse_url(urldecode($url));
changes %26 to ampersand which triggers expectation of another $input key and value pair.

It seems the solution is to change 1485 to
 		$parsed_url = @parse_url($url);
since the properly parsed elements are reassembled into a url for use in the video template, which would work just as well encoded with %26.

That all is background for the question.
What further purpose does urldecode() have in line 1485 that would warrant keeping it in?