Skip to content

Commit

Permalink
MDL-59255 core: Add rtmp:// support to validateUrlSyntax function.
Browse files Browse the repository at this point in the history
  • Loading branch information
kabalin committed Jul 18, 2017
1 parent 16a68a2 commit 646e8bf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
6 changes: 6 additions & 0 deletions lib/thirdpartylibs.xml
Expand Up @@ -304,4 +304,10 @@
<version>4.7.0</version>
<licenseversion>1.1</licenseversion>
</library>
<library>
<location>validateurlsyntax.php</location>
<name>Url Syntax Validation using PHP and Regular Expressions</name>
<license>GPL</license>
<licenseversion>2.0+</licenseversion>
</library>
</libraries>
14 changes: 11 additions & 3 deletions lib/validateurlsyntax.php
Expand Up @@ -76,10 +76,13 @@
* </code>
*
* Last Edited:
* December 15th 2004
* June 15th 2017
*
*
* Changelog:
* June 15th 2017 by Moodle.
* -Added rtmp:// option.
*
* December 15th 2004
* -Added new TLD's - .jobs, .mobi, .post and .travel. They are official, but not yet active.
*
Expand Down Expand Up @@ -174,7 +177,7 @@ function validateUrlSyntax( $urladdr, $options="" ){
// $options = strtolower($options);

// Check Options Parameter
if (!preg_match( '/^([sHSEFuPaIpfqr][+?-])*$/', $options ))
if (!preg_match( '/^([sHSEFRuPaIpfqr][+?-])*$/', $options ))
{
trigger_error("Options attribute malformed", E_USER_ERROR);
}
Expand All @@ -195,6 +198,9 @@ function validateUrlSyntax( $urladdr, $options="" ){
// ftp://
if (strpos( $options, 'F') === false) $aOptions['F'] = '-';
else $aOptions['F'] = substr( $options, strpos( $options, 'F') + 1, 1);
// rtmp://
if (strpos( $options, 'R') === false) $aOptions['R'] = '-';
else $aOptions['R'] = substr( $options, strpos( $options, 'R') + 1, 1);
// User section
if (strpos( $options, 'u') === false) $aOptions['u'] = '?';
else $aOptions['u'] = substr( $options, strpos( $options, 'u') + 1, 1);
Expand Down Expand Up @@ -245,18 +251,20 @@ function validateUrlSyntax( $urladdr, $options="" ){
$reserved = '[;/?:@&=+$,]'; // Special characters in the URI

// Beginning Regular Expression
// Scheme - Allows for 'http://', 'https://', 'mailto:', or 'ftp://'
// Scheme - Allows for 'http://', 'https://', 'mailto:', 'ftp://' or 'rtmp://'
$scheme = '(';
if ($aOptions['H'] === '') { $scheme .= 'http://'; }
elseif ($aOptions['S'] === '') { $scheme .= 'https://'; }
elseif ($aOptions['E'] === '') { $scheme .= 'mailto:'; }
elseif ($aOptions['F'] === '') { $scheme .= 'ftp://'; }
elseif ($aOptions['R'] === '') { $scheme .= 'rtmp://'; }
else
{
if ($aOptions['H'] === '?') { $scheme .= '|(http://)'; }
if ($aOptions['S'] === '?') { $scheme .= '|(https://)'; }
if ($aOptions['E'] === '?') { $scheme .= '|(mailto:)'; }
if ($aOptions['F'] === '?') { $scheme .= '|(ftp://)'; }
if ($aOptions['R'] === '?') { $scheme .= '|(rtmp://)'; }
$scheme = str_replace('(|', '(', $scheme); // fix first pipe
}
$scheme .= ')' . $aOptions['s'];
Expand Down

0 comments on commit 646e8bf

Please sign in to comment.