diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 1e9bdf4f180..8a9960d5356 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -182,6 +182,11 @@ define('PARAM_PERMISSION', 'permission'); */ define('PARAM_RAW', 'raw'); +/** + * PARAM_RAW_TRIMMED like PARAM_RAW but leading and trailing whitespace is stripped. + */ +define('PARAM_RAW_TRIMMED', 'raw_trimmed'); + /** * PARAM_SAFEDIR - safe directory name, suitable for include() and require() */ @@ -553,6 +558,9 @@ function clean_param($param, $type) { case PARAM_RAW: // no cleaning at all return $param; + case PARAM_RAW_TRIMMED: // no cleaning, but strip leading and trailing whitespace. + return trim($param); + case PARAM_CLEAN: // General HTML cleaning, try to use more specific type if possible // this is deprecated!, please use more specific type instead if (is_numeric($param)) { diff --git a/lib/simpletest/testmoodlelib.php b/lib/simpletest/testmoodlelib.php index c6615382e4f..2f8ca704b1c 100644 --- a/lib/simpletest/testmoodlelib.php +++ b/lib/simpletest/testmoodlelib.php @@ -313,6 +313,10 @@ class moodlelib_test extends UnitTestCase { '#()*#,9789\'".,<42897>assertEqual(clean_param(" Frog toad \r\n ", PARAM_RAW_TRIMMED), 'Frog toad'); + } + function test_clean_param_clean() { // PARAM_CLEAN is an ugly hack, do not use in new code (skodak) // instead use more specific type, or submit sothing that can be verified properly