0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -05:00

ensure null query options don't break ghost-url

closes #6565
This commit is contained in:
Austin Burdine 2016-02-29 00:25:38 -06:00
parent bd3622b980
commit 193e033f99
2 changed files with 27 additions and 3 deletions

View file

@ -33,12 +33,15 @@
queryOptions,
requestUrl = apiUrl;
if (args.length && typeof args[args.length - 1] === 'object') {
queryOptions = args.pop();
} else {
queryOptions = args.pop();
if (queryOptions && typeof queryOptions !== 'object') {
args.push(queryOptions);
queryOptions = {};
}
queryOptions = queryOptions || {};
queryOptions.client_id = clientId;
queryOptions.client_secret = clientSecret;

View file

@ -73,6 +73,27 @@ describe('Ghost Ajax Helper', function () {
rendered.should.match(/c=en\%20coded/);
});
it('handles null/undefined queryOptions correctly', function () {
ghostUrl.init({
clientId: 'ghost-frontend',
clientSecret: 'notasecret',
url: 'test'
});
var test = {
a: null
},
rendered = ghostUrl.url.api(test.a), // null value
rendered2 = ghostUrl.url.api(test.b); // undefined value
rendered.should.match(/test/);
rendered.should.match(/client_id=ghost-frontend/);
rendered.should.match(/client_secret=notasecret/);
rendered2.should.match(/test/);
rendered2.should.match(/client_id=ghost-frontend/);
rendered2.should.match(/client_secret=notasecret/);
});
it('generates complex query correctly', function () {
ghostUrl.init({
clientId: 'ghost-frontend',