diff --git a/core/server/apps/amp/tests/amp_content_spec.js b/core/server/apps/amp/tests/amp_content_spec.js index 6a8715a98e..e936741e83 100644 --- a/core/server/apps/amp/tests/amp_content_spec.js +++ b/core/server/apps/amp/tests/amp_content_spec.js @@ -263,6 +263,29 @@ describe('{{amp_content}} helper', function () { }).catch(done); }); + it('does not convert internal anchor links starting with "#"', function (done) { + var testData = { + html: 'Table of Content', + updated_at: 'Wed Jul 27 2016 18:17:22 GMT+0200 (CEST)', + id: 1 + }, + ampResult = ampContentHelper.call(testData), + sanitizedHTML, + ampedHTML; + + ampResult.then(function (rendered) { + sanitizedHTML = ampContentHelper.__get__('cleanHTML'); + ampedHTML = ampContentHelper.__get__('ampHTML'); + should.exist(rendered); + rendered.string.should.equal('Table of Content'); + should.exist(ampedHTML); + ampedHTML.should.be.equal('Table of Content'); + should.exist(sanitizedHTML); + sanitizedHTML.should.be.equal('Table of Content'); + done(); + }).catch(done); + }); + it('sanitizes remaining and not valid tags', function (done) { var testData = { html: '' + diff --git a/core/server/utils/make-absolute-urls.js b/core/server/utils/make-absolute-urls.js index d7dd07079e..62053ad0f7 100644 --- a/core/server/utils/make-absolute-urls.js +++ b/core/server/utils/make-absolute-urls.js @@ -41,6 +41,10 @@ function makeAbsoluteUrls(html, siteUrl, itemUrl) { return; } + // CASE: don't convert internal links + if (attributeValue[0] === '#') { + return; + } // compose an absolute URL // if the relative URL begins with a '/' use the blog URL (including sub-directory) diff --git a/core/test/unit/rss_spec.js b/core/test/unit/rss_spec.js index e34ee3af37..2c424cf551 100644 --- a/core/test/unit/rss_spec.js +++ b/core/test/unit/rss_spec.js @@ -223,7 +223,7 @@ describe('RSS', function () { should.exist(xmlData); // anchor URL - - xmlData.should.match(//); + xmlData.should.match(//); // relative URL - xmlData.should.match(//); @@ -258,7 +258,7 @@ describe('RSS', function () { should.exist(xmlData); // anchor URL - - xmlData.should.match(//); + xmlData.should.match(//); // relative URL - xmlData.should.match(//); diff --git a/core/test/unit/utils/make-absolute-urls_spec.js b/core/test/unit/utils/make-absolute-urls_spec.js index 399e22a54e..e2df0364f9 100644 --- a/core/test/unit/utils/make-absolute-urls_spec.js +++ b/core/test/unit/utils/make-absolute-urls_spec.js @@ -14,25 +14,31 @@ describe('Make absolute URLs ', function () { configUtils.restore(); }); - it('does not convert absolute URLs', function () { + it('[success] does not convert absolute URLs', function () { var html = '', result = makeAbsoluteUrls(html, siteUrl, itemUrl).html(); result.should.match(//); }); - it('does not convert protocol relative `//` URLs', function () { + it('[failure] does not convert protocol relative `//` URLs', function () { var html = '', result = makeAbsoluteUrls(html, siteUrl, itemUrl).html(); result.should.match(//); }); - it('succesfully converts a relative URL', function () { + it('[failure] does not convert internal links starting with "#"', function () { + var html = '', + result = makeAbsoluteUrls(html, siteUrl, itemUrl).html(); + + result.should.match(//); + }); + it('[success] converts a relative URL', function () { var html = '', result = makeAbsoluteUrls(html, siteUrl, itemUrl).html(); result.should.match(//); }); - it('succesfully converts a relative URL including subdirectories', function () { + it('[success] converts a relative URL including subdirectories', function () { var html = '', result = makeAbsoluteUrls(html, 'http://my-ghost-blog.com/blog', itemUrl).html();