Add support for javascript object notation in allowed JSONP callback

This commit is contained in:
aripringle 2012-05-18 17:03:28 -06:00
parent 18132c18b4
commit 4fa8e68cdc

View File

@ -55,8 +55,11 @@ class JsonResponse extends Response
if ($callback) {
// taken from http://www.geekality.net/2011/08/03/valid-javascript-identifier/
$pattern = '/^[$_\p{L}][$_\p{L}\p{Mn}\p{Mc}\p{Nd}\p{Pc}\x{200C}\x{200D}]*+$/u';
if (!preg_match($pattern, $callback)) {
throw new \InvalidArgumentException('The callback name is not valid.');
$parts = explode('.', $callback);
foreach ($parts as $part) {
if (!preg_match($pattern, $part)) {
throw new \InvalidArgumentException('The callback name is not valid.');
}
}
}