diff --git a/lib/SimpleSAML/Utilities.php b/lib/SimpleSAML/Utilities.php index 9155f0ecac2d32545bab14c3df6878643c637ff4..51185e843660fbef6d8b71aefcedbe70efc04d25 100644 --- a/lib/SimpleSAML/Utilities.php +++ b/lib/SimpleSAML/Utilities.php @@ -1095,6 +1095,37 @@ class SimpleSAML_Utilities { return $baseHost . $dir . $tail; } + + /** + * Parse a query string into an array. + * + * This function parses a query string into an array, similar to the way the builtin + * 'parse_str' works, except it doesn't handle arrays, and it doesn't do "magic quotes". + * + * Query parameters without values will be set to an empty string. + * + * @param $query_string The query string which should be parsed. + * @return The query string as an associative array. + */ + public function parseQueryString($query_string) { + assert('is_string($query_string)'); + + $res = array(); + foreach(split('&', $query_string) as $param) { + $param = split('=', $param); + $name = urldecode($param[0]); + if(count($param) === 1) { + $value = ''; + } else { + $value = urldecode($param[1]); + } + + $res[$name] = $value; + } + + return $res; + } + } ?> \ No newline at end of file