Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parsing url with url in parameter #771

Open
wants to merge 1 commit into
base: MOODLE_39_STABLE
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions classes/idp_parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,32 @@ public function parse_urls($urls) {
continue;
}

// @COREHACK fix-parsing-url-with-url-in-parameter.
// Separate out query strings from the URL prefix and build a line without query strings.
$start = strpos($line, "http");
if ($start === false) {
$terms = array();
} else {
$terms = explode(" ", substr($line, $start));
$line = substr($line, 0, $start);
}

$parameters = array();
$clean = "";
foreach ($terms as $term) {
$p = strpos($term, "?");
if ($p >= 1) {
$parameters[] = substr($term, $p);
$left = substr($term, 0, $p);
} else {
$parameters[] = "";
$left = $term;
}
$clean .= $left . " ";
}
$line .= trim($clean);
// END COREHACK fix-parsing-url-with-url-in-parameter.

// Separate the line base on the scheme http. The scheme added back to the urls.
$parts = array_map('rtrim', explode($scheme, $line));

Expand All @@ -113,6 +139,15 @@ public function parse_urls($urls) {
$idpurl = $scheme . $parts[1];
$idpicon = $scheme . $parts[2];

// @COREHACK fix-parsing-url-with-url-in-parameter.
if ($parameters[0]) {
$idpurl .= $parameters[0];
}
if ($parameters[1]) {
$idpicon .= $parameters[1];
}
// END COREHACK fix-parsing-url-with-url-in-parameter.

$idpdata = new \auth_saml2\idp_data($idpname, $idpurl, $idpicon);

} else if (count($parts) === 2) {
Expand All @@ -124,18 +159,40 @@ public function parse_urls($urls) {
$idpurl = $scheme . $parts[1];
$idpicon = $scheme . $parts[2];

// @COREHACK fix-parsing-url-with-url-in-parameter.
if ($parameters[0]) {
$idpurl .= $parameters[0];
}
if ($parameters[1]) {
$idpicon .= $parameters[1];
}
// END COREHACK fix-parsing-url-with-url-in-parameter.

$idpdata = new \auth_saml2\idp_data(null, $idpurl, $idpicon);
} else {
// We would then know that is a IdPName + IdPURL combo.
$idpname = $parts[0];
$idpurl = $scheme . $parts[1];

// @COREHACK fix-parsing-url-with-url-in-parameter.
if ($parameters[0]) {
$idpurl .= $parameters[0];
}
// END COREHACK fix-parsing-url-with-url-in-parameter.

$idpdata = new \auth_saml2\idp_data($idpname, $idpurl, null);
}

} else if (count($parts) === 1) {
// One element is the previous default.
$idpurl = $scheme . $parts[0];

// @COREHACK fix-parsing-url-with-url-in-parameter.
if ($parameters[0]) {
$idpurl .= $parameters[0];
}
// END COREHACK fix-parsing-url-with-url-in-parameter.

$idpdata = new \auth_saml2\idp_data(null, $idpurl, null);
}

Expand Down