mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 00:46:50 +02:00
MDL-59198 lti: Make params LTI2 compatible
LTI2 recommends to include both upper case and lower case of custom params. This patch makes our implementation confer to that standard.
This commit is contained in:
parent
27466d7548
commit
e4f7cfe19f
2 changed files with 17 additions and 8 deletions
|
@ -1165,7 +1165,7 @@ function lti_get_enabled_capabilities($tool) {
|
|||
* @param string $customstr String containing the parameters
|
||||
* @param boolean $islti2 True if an LTI 2 tool is being launched
|
||||
*
|
||||
* @return Array of custom parameters
|
||||
* @return array of custom parameters
|
||||
*/
|
||||
function lti_split_custom_parameters($toolproxy, $tool, $params, $customstr, $islti2 = false) {
|
||||
$customstr = str_replace("\r\n", "\n", $customstr);
|
||||
|
@ -1179,11 +1179,12 @@ function lti_split_custom_parameters($toolproxy, $tool, $params, $customstr, $is
|
|||
continue;
|
||||
}
|
||||
$key = trim(core_text::substr($line, 0, $pos));
|
||||
$key = lti_map_keyname($key, false);
|
||||
$val = trim(core_text::substr($line, $pos + 1, strlen($line)));
|
||||
$val = lti_parse_custom_parameter($toolproxy, $tool, $params, $val, $islti2);
|
||||
$key2 = lti_map_keyname($key);
|
||||
$retval['custom_'.$key2] = $val;
|
||||
if ($islti2 && ($key != $key2)) {
|
||||
if ($key != $key2) {
|
||||
$retval['custom_'.$key] = $val;
|
||||
}
|
||||
}
|
||||
|
@ -1269,14 +1270,16 @@ function lti_parse_custom_parameter($toolproxy, $tool, $params, $value, $islti2)
|
|||
* Used for building the names of the different custom parameters
|
||||
*
|
||||
* @param string $key Parameter name
|
||||
*
|
||||
* @param bool $tolower Do we want to convert the key into lower case?
|
||||
* @return string Processed name
|
||||
*/
|
||||
function lti_map_keyname($key) {
|
||||
function lti_map_keyname($key, $tolower = true) {
|
||||
$newkey = "";
|
||||
if ($tolower) {
|
||||
$key = core_text::strtolower(trim($key));
|
||||
}
|
||||
foreach (str_split($key) as $ch) {
|
||||
if ( ($ch >= 'a' && $ch <= 'z') || ($ch >= '0' && $ch <= '9') ) {
|
||||
if ( ($ch >= 'a' && $ch <= 'z') || ($ch >= '0' && $ch <= '9') || (!$tolower && ($ch >= 'A' && $ch <= 'Z'))) {
|
||||
$newkey .= $ch;
|
||||
} else {
|
||||
$newkey .= '_';
|
||||
|
|
|
@ -71,14 +71,20 @@ class mod_lti_locallib_testcase extends advanced_testcase {
|
|||
$this->assertEquals(lti_split_custom_parameters(null, $tool, array(), "x=1\ny=2", false),
|
||||
array('custom_x' => '1', 'custom_y' => '2'));
|
||||
|
||||
// Check params with caps.
|
||||
$this->assertEquals(lti_split_custom_parameters(null, $tool, array(), "X=1", false),
|
||||
array('custom_x' => '1', 'custom_X' => '1'));
|
||||
|
||||
// Removed repeat of previous test with a semicolon separator.
|
||||
|
||||
$this->assertEquals(lti_split_custom_parameters(null, $tool, array(), 'Review:Chapter=1.2.56', false),
|
||||
array('custom_review_chapter' => '1.2.56'));
|
||||
array('custom_review_chapter' => '1.2.56', 'custom_Review_Chapter' => '1.2.56'));
|
||||
|
||||
$this->assertEquals(lti_split_custom_parameters(null, $tool, array(),
|
||||
'Complex!@#$^*(){}[]KEY=Complex!@#$^*;(){}[]½Value', false),
|
||||
array('custom_complex____________key' => 'Complex!@#$^*;(){}[]½Value'));
|
||||
array(
|
||||
'custom_complex____________key' => 'Complex!@#$^*;(){}[]½Value',
|
||||
'custom_Complex____________KEY' => 'Complex!@#$^*;(){}[]½Value'));
|
||||
|
||||
// Test custom parameter that returns $USER property.
|
||||
$user = $this->getDataGenerator()->create_user(array('middlename' => 'SOMETHING'));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue