Skip to content

Commit

Permalink
MDL-46269 tool_httpsreplace: Make param search case insensitive
Browse files Browse the repository at this point in the history
  • Loading branch information
xow authored and marinaglancy committed Oct 16, 2017
1 parent 6163651 commit 4b86dd7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions admin/tool/httpsreplace/classes/url_finder.php
Expand Up @@ -153,15 +153,15 @@ private function process($replacing = false, $progress = null) {

if (in_array($column->type, $texttypes)) {
$columnname = $column->name;
$select = "$columnname $regexp ?";
$select = "LOWER($columnname) $regexp ?";
$rs = $DB->get_recordset_select($table, $select, [$httpurls]);

$found = array();
foreach ($rs as $record) {
// Regex to match src=http://etc. and data=http://etc.urls.
// Standard warning on expecting regex to perfectly parse HTML
// read http://stackoverflow.com/a/1732454 for more info.
$regex = '#(src|data)\ *=\ *[\'\"]http://[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/))[\'\"]#';
$regex = '#(src|data)\ *=\ *[\'\"]http://[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/))[\'\"]#i';
preg_match_all($regex, $record->$columnname, $match);
foreach ($match[0] as $url) {
if (strpos($url, $CFG->wwwroot) !== false) {
Expand Down
5 changes: 5 additions & 0 deletions admin/tool/httpsreplace/tests/httpsreplace_test.php
Expand Up @@ -74,6 +74,11 @@ public function upgrade_http_links_provider() {
"outputregex" => '/^$/',
"expectedcontent" => '<img src="https://anothersite.com?param=http://asdf.com">',
],
"Search for params should be case insensitive" => [
"content" => '<object DATA="' . $this->getExternalTestFileUrl('/test.swf', false) . '">',
"outputregex" => '/UPDATE/',
"expectedcontent" => '<object DATA="' . $this->getExternalTestFileUrl('/test.swf', true) . '">',
],
"More params should not interfere" => [
"content" => '<img alt="A picture" src="' . $this->getExternalTestFileUrl('/test.png', false) . '" width="1”><p style="font-size: \'20px\'"></p>',
"outputregex" => '/UPDATE/',
Expand Down

0 comments on commit 4b86dd7

Please sign in to comment.