зеркало из https://github.com/mozilla/popcorn-js.git
[#t1219] Allow JSONP to have arbitrary callback params with placeholder "?" values
Signed-off-by: Rick Waldron <waldron.rick@gmail.com>
This commit is contained in:
Родитель
de9d2f2ca4
Коммит
88b7aff24b
|
@ -186,7 +186,7 @@
|
|||
|
||||
var scriptReady = function() {
|
||||
|
||||
Popcorn.getJSONP( "//000000book.com/data/" + options.gmltag + ".json?callback=", function( data ) {
|
||||
Popcorn.getJSONP( "//000000book.com/data/" + options.gmltag + ".json?callback=?", function( data ) {
|
||||
|
||||
options.pjsInstance = new Processing( options.container, gmlPlayer );
|
||||
options.pjsInstance.construct( self.media, data, options );
|
||||
|
|
|
@ -341,7 +341,7 @@
|
|||
type = "info";
|
||||
}
|
||||
requestString = "http://api.tumblr.com/v2/blog/" + options.base_hostname + "/" + type + "?api_key=" + options.api_key + "&id=" + options.blogId +
|
||||
"&jsonp=tumblrCallBack";
|
||||
"&jsonp=?";
|
||||
|
||||
if ( options.base_hostname && options.base_hostname !== "" && options.api_key && options.blogId ) {
|
||||
|
||||
|
|
23
popcorn.js
23
popcorn.js
|
@ -2025,17 +2025,30 @@
|
|||
script = document.createElement( "script" ),
|
||||
isFired = false,
|
||||
params = [],
|
||||
paramStr, callback, callparam;
|
||||
rjsonp = /(=)\?(?=&|$)|\?\?/,
|
||||
replaceInUrl, prefix, paramStr, callback, callparam;
|
||||
|
||||
if ( !isScript ) {
|
||||
|
||||
// is there a calback already in the url
|
||||
callparam = url.match( /(callback=[^&]*)/ );
|
||||
|
||||
if ( callparam ) {
|
||||
if ( callparam !== null && callparam.length ) {
|
||||
|
||||
prefix = callparam[ 1 ].split( "=" )[ 1 ];
|
||||
|
||||
// Since we need to support developer specified callbacks
|
||||
// and placeholders in harmony, make sure matches to "callback="
|
||||
// aren't just placeholders.
|
||||
// We coded ourselves into a corner here.
|
||||
// JSONP callbacks should never have been
|
||||
// allowed to have developer specified callbacks
|
||||
if ( prefix === "?" ) {
|
||||
prefix = "jsonp";
|
||||
}
|
||||
|
||||
// get the callback name
|
||||
callback = Popcorn.guid( callparam[ 1 ].split( "=" )[ 1 ] );
|
||||
callback = Popcorn.guid( prefix );
|
||||
|
||||
// replace existing callback name with unique callback name
|
||||
url = url.replace( /(callback=[^&]*)/, "callback=" + callback );
|
||||
|
@ -2043,6 +2056,10 @@
|
|||
|
||||
callback = Popcorn.guid( "jsonp" );
|
||||
|
||||
if ( rjsonp.test( url ) ) {
|
||||
url = url.replace( rjsonp, "$1" + callback );
|
||||
}
|
||||
|
||||
// split on first question mark,
|
||||
// this is to capture the query string
|
||||
params = url.split( /\?(.+)?/ );
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
$callback = $_REQUEST['callback'];
|
||||
$callback = isset($_REQUEST['callback']) ? $_REQUEST['callback'] : $_REQUEST['jsonp'];
|
||||
|
||||
if ( !$callback ) {
|
||||
|
||||
|
@ -11,4 +11,4 @@ if ( !$callback ) {
|
|||
|
||||
echo $callback . '({ "data": {"lang": "en", "length": 25} });';
|
||||
|
||||
?>
|
||||
?>
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
|
||||
$callback = $_REQUEST['jsonpfancyapi'];
|
||||
|
||||
if ( !$callback ) {
|
||||
|
||||
echo 'Invalid Parameter';
|
||||
|
||||
} else {
|
||||
echo $callback . '({ "data": {"lang": "en", "length": 25} });';
|
||||
}
|
||||
|
||||
|
||||
|
||||
?>
|
|
@ -4844,21 +4844,7 @@ if ( !/file/.test( location.protocol ) ) {
|
|||
});
|
||||
});
|
||||
|
||||
test( "JSONP xhr.getJSONP Response", function() {
|
||||
|
||||
var expects = 2,
|
||||
count = 0;
|
||||
|
||||
function plus() {
|
||||
if ( ++count === expects ) {
|
||||
start();
|
||||
}
|
||||
}
|
||||
|
||||
expect( expects );
|
||||
|
||||
stop();
|
||||
|
||||
asyncTest( "JSONP xhr.getJSONP Response", 2, function() {
|
||||
var testObj = {
|
||||
"data": {
|
||||
"lang": "en",
|
||||
|
@ -4868,13 +4854,22 @@ if ( !/file/.test( location.protocol ) ) {
|
|||
|
||||
Popcorn.xhr.getJSONP(
|
||||
|
||||
"data/jsonp.php?callback=jsonp",
|
||||
"data/jsonp.php?callback=?",
|
||||
function( data ) {
|
||||
|
||||
ok( data, "getJSONP returns data" );
|
||||
plus();
|
||||
ok( QUnit.equiv(data, testObj) , "Popcorn.xhr.getJSONP data.json returns an object of data" );
|
||||
plus();
|
||||
deepEqual( data, testObj, "Popcorn.xhr.getJSONP data.json returns an object of data" );
|
||||
start();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
asyncTest( "JSONP xhr.getJSONP, strictly enforced parameter with callback placeholder", 1, function() {
|
||||
Popcorn.xhr.getJSONP(
|
||||
"data/jsonpfancyapi.php?jsonpfancyapi=?",
|
||||
function( data ) {
|
||||
ok( data, "getJSONP with placeholder callback name returns data" );
|
||||
start();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче