-
Bug
-
Resolution: Fixed
-
Minor
-
2.9.2, 3.1.14, 3.3.8, 3.4.5, 3.5.2
-
MOODLE_29_STABLE, MOODLE_31_STABLE, MOODLE_33_STABLE, MOODLE_34_STABLE, MOODLE_35_STABLE
-
MOODLE_34_STABLE, MOODLE_35_STABLE
-
MDL-51969-master -
Explanation
The 'tc_profile_url' is determined by the get_endpoint() function in mod/lti/classes/local/ltiservice/service_base.php:
public function get_endpoint() {
|
|
$this->parse_template();
|
$url = $this->get_service()->get_service_path() . $this->get_template();
|
foreach ($this->params as $key => $value) {
|
$url = str_replace('{' . $key . '}', $value, $url);
|
}
|
$toolproxy = $this->get_service()->get_tool_proxy();
|
if (!empty($toolproxy)) {
|
$url = str_replace('{tool_proxy_id}', $toolproxy->guid, $url);
|
}
|
|
return $url;
|
|
}
|
The function calls parse_template() which determines the '{tool_proxy_id}' parameter from the PATH_INFO environment variable. If not set the '{tool_proxy_id}' parameter is set to the guid of the tool proxy.
Now look at the parse_template() function:
protected function parse_template() {
|
|
if (empty($this->params)) {
|
$this->params = array();
|
if (isset($_SERVER['PATH_INFO'])) {
|
$path = explode('/', $_SERVER['PATH_INFO']);
|
$parts = explode('/', $this->get_template());
|
for ($i = 0; $i < count($parts); $i++) {
|
if ((substr($parts[$i], 0, 1) == '{') && (substr($parts[$i], -1) == '}')) {
|
$value = '';
|
if ($i < count($path)) {
|
$value = $path[$i];
|
}
|
$this->params[substr($parts[$i], 1, -1)] = $value;
|
}
|
}
|
}
|
}
|
|
return $this->params;
|
|
}
|
If the PATH_INFO variable is not set the function returns an empty array. But if the PATH_INFO variable is an empty string the function sets all parameters to an empty string. As a result the '{tool_proxy_id}' parameter is set to an empty string and won't be replaced with the tool proxy guid by get_endpoint() anymore.
Workaround/ProposedFix
Check in parse_template() if the PATH_INFO variable is empty:
$ git diff
|
diff --git a/mod/lti/classes/local/ltiservice/resource_base.php b/mod/lti/classes/local/ltiservice/resource_base.php
|
index 4d617fe..60c7327 100644
|
--- a/mod/lti/classes/local/ltiservice/resource_base.php
|
+++ b/mod/lti/classes/local/ltiservice/resource_base.php
|
@@ -255,7 +255,7 @@ abstract class resource_base {
|
|
if (empty($this->params)) {
|
$this->params = array();
|
- if (isset($_SERVER['PATH_INFO'])) {
|
+ if (isset($_SERVER['PATH_INFO']) && !empty($_SERVER['PATH_INFO'])) {
|
$path = explode('/', $_SERVER['PATH_INFO']);
|
$parts = explode('/', $this->get_template());
|
for ($i = 0; $i < count($parts); $i++) {
|
Note that according to RFC 3875, section 4.1.5, an empty PATH_INFO variable is perfectly correct:
PATH_INFO = "" | ( "/" path )