From 89f124b5771ef1688f691cba4b7ec68446975a1c Mon Sep 17 00:00:00 2001 From: Eric Kelly Date: Wed, 20 Jan 2016 22:10:46 -0500 Subject: [PATCH] [BUGFIX beta] Fix `BuildUrlMixin.urlPrefix` regression when host is "/" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes https://github.com/emberjs/data/issues/4105 I couldn't think of a better name for the test ¯\_(ツ)_/¯ --- addon/-private/adapters/build-url-mixin.js | 6 +++++- .../adapter/build-url-mixin-test.js | 20 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/addon/-private/adapters/build-url-mixin.js b/addon/-private/adapters/build-url-mixin.js index f67cc558e3d..07ab6d79e68 100644 --- a/addon/-private/adapters/build-url-mixin.js +++ b/addon/-private/adapters/build-url-mixin.js @@ -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)) { diff --git a/tests/integration/adapter/build-url-mixin-test.js b/tests/integration/adapter/build-url-mixin-test.js index a1c53ce9737..7f6bf98e67c 100644 --- a/tests/integration/adapter/build-url-mixin-test.js +++ b/tests/integration/adapter/build-url-mixin-test.js @@ -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',