Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX beta] Fix BuildUrlMixin.urlPrefix regression when host=/ #4108

Merged
merged 1 commit into from
Jan 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion addon/-private/adapters/build-url-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,13 @@ export default Ember.Mixin.create({
@return {String} urlPrefix
*/
urlPrefix(path, parentURL) {
var host = get(this, 'host') || '';
var host = get(this, 'host');
var namespace = get(this, 'namespace');

if (!host || host === '/') {
host = '';
}

if (path) {
// Protocol relative url
if (/^\/\//.test(path) || /http(s)?:\/\//.test(path)) {
Expand Down
20 changes: 20 additions & 0 deletions tests/integration/adapter/build-url-mixin-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,26 @@ test('buildURL - with absolute paths in links and protocol relative host', funct
}));
});

test('buildURL - with absolute paths in links and host is /', function(assert) {
run(function() {
adapter.setProperties({
host: '/',
namespace: 'api/v1'
});
});
Post.reopen({ comments: DS.hasMany('comment', { async: true }) });
Comment.reopen({ post: DS.belongsTo('post', { async: false }) });

ajaxResponse({ posts: [{ id: 1, links: { comments: '/api/v1/posts/1/comments' } }] });

run(store, 'findRecord', 'post', 1).then(assert.wait(function(post) {
ajaxResponse({ comments: [{ id: 1 }] });
return post.get('comments');
})).then(assert.wait(function (comments) {
assert.equal(passedUrl, '/api/v1/posts/1/comments', 'host stripped out properly');
}));
});

test('buildURL - with full URLs in links', function(assert) {
adapter.setProperties({
host: 'http://example.com',
Expand Down