mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-19 16:42:17 +03:00
7d388cb9e1
closes #9136 Changed the functionality in `make-absolute-urls.js` util to not convert the URL when starting which an `#`, as it indicates and internal link. The util is used inside of the `{{amp_content}}` helper and to render the RSS feed. I tested the changes with the most popular RSS reader 'Feedly' and it seems like these internal links get converted to absolute URL inside of Feedly automatically.
48 lines
2.1 KiB
JavaScript
48 lines
2.1 KiB
JavaScript
var should = require('should'), // jshint ignore:line
|
|
makeAbsoluteUrls = require('../../../server/utils/make-absolute-urls'),
|
|
configUtils = require('../../utils/configUtils');
|
|
|
|
describe('Make absolute URLs ', function () {
|
|
var siteUrl = 'http://my-ghost-blog.com',
|
|
itemUrl = 'my-awesome-post';
|
|
|
|
beforeEach(function () {
|
|
configUtils.set({url: 'http://my-ghost-blog.com'});
|
|
});
|
|
|
|
afterEach(function () {
|
|
configUtils.restore();
|
|
});
|
|
|
|
it('[success] does not convert absolute URLs', function () {
|
|
var html = '<a href="http://my-ghost-blog.com/content/images" title="Absolute URL">',
|
|
result = makeAbsoluteUrls(html, siteUrl, itemUrl).html();
|
|
|
|
result.should.match(/<a href="http:\/\/my-ghost-blog.com\/content\/images" title="Absolute URL">/);
|
|
});
|
|
it('[failure] does not convert protocol relative `//` URLs', function () {
|
|
var html = '<a href="//my-ghost-blog.com/content/images" title="Absolute URL">',
|
|
result = makeAbsoluteUrls(html, siteUrl, itemUrl).html();
|
|
|
|
result.should.match(/<a href="\/\/my-ghost-blog.com\/content\/images" title="Absolute URL">/);
|
|
});
|
|
it('[failure] does not convert internal links starting with "#"', function () {
|
|
var html = '<a href="#jumptosection" title="Table of Content">',
|
|
result = makeAbsoluteUrls(html, siteUrl, itemUrl).html();
|
|
|
|
result.should.match(/<a href="#jumptosection" title="Table of Content">/);
|
|
});
|
|
it('[success] converts a relative URL', function () {
|
|
var html = '<a href="/about#nowhere" title="Relative URL">',
|
|
result = makeAbsoluteUrls(html, siteUrl, itemUrl).html();
|
|
|
|
result.should.match(/<a href="http:\/\/my-ghost-blog.com\/about#nowhere" title="Relative URL">/);
|
|
});
|
|
it('[success] converts a relative URL including subdirectories', function () {
|
|
var html = '<a href="/about#nowhere" title="Relative URL">',
|
|
result = makeAbsoluteUrls(html, 'http://my-ghost-blog.com/blog', itemUrl).html();
|
|
|
|
result.should.match(/<a href="http:\/\/my-ghost-blog.com\/blog\/about#nowhere" title="Relative URL">/);
|
|
});
|
|
});
|