mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-03 03:55:26 +03:00
f7129a0e39
no issue This PR takes the existing function `processUrls` in `data/xml/rss` and refactors it to be a stand-alone util. The change is needed, as this functionality will be accessed from `apps/amp` to convert relative URLs.
40 lines
1.8 KiB
JavaScript
40 lines
1.8 KiB
JavaScript
var 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('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('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('succesfully 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('succesfully 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">/);
|
|
});
|
|
});
|