0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-03 23:00:14 -05:00

Merge pull request #6566 from acburdine/ghost-url-fix

Ensure null query options don't break ghost-url
This commit is contained in:
Hannah Wolfe 2016-03-02 18:39:56 +00:00
commit 4a2944d36a
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',