mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
fix: regression caused by cc6fd49c4d
This commit is contained in:
@@ -88,16 +88,9 @@ module.exports = function (Posts) {
|
|||||||
while (current !== null) {
|
while (current !== null) {
|
||||||
if (current[1]) {
|
if (current[1]) {
|
||||||
try {
|
try {
|
||||||
parsed = new URL(current[1]);
|
parsed = new URL(current[1], nconf.get('url'));
|
||||||
if (!parsed.protocol) {
|
absolute = parsed.toString();
|
||||||
if (current[1].startsWith('/')) {
|
if (absolute !== current[1]) {
|
||||||
// Internal link
|
|
||||||
absolute = nconf.get('base_url') + current[1];
|
|
||||||
} else {
|
|
||||||
// External link
|
|
||||||
absolute = `//${current[1]}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
const offset = current[0].indexOf(current[1]);
|
const offset = current[0].indexOf(current[1]);
|
||||||
content = content.slice(0, current.index + offset) +
|
content = content.slice(0, current.index + offset) +
|
||||||
absolute +
|
absolute +
|
||||||
|
|||||||
@@ -763,18 +763,18 @@ describe('Post\'s', () => {
|
|||||||
|
|
||||||
it('should turn relative links in post body to absolute urls', (done) => {
|
it('should turn relative links in post body to absolute urls', (done) => {
|
||||||
const nconf = require('nconf');
|
const nconf = require('nconf');
|
||||||
const content = '<a href="/users">test</a> <a href="youtube.com">youtube</a>';
|
const content = '<a href="/users">test</a> <a href="//youtube.com">youtube</a>';
|
||||||
const parsedContent = posts.relativeToAbsolute(content, posts.urlRegex);
|
const parsedContent = posts.relativeToAbsolute(content, posts.urlRegex);
|
||||||
assert.equal(parsedContent, `<a href="${nconf.get('base_url')}/users">test</a> <a href="//youtube.com">youtube</a>`);
|
assert.equal(parsedContent, `<a href="${nconf.get('base_url')}/users">test</a> <a href="https://youtube.com/">youtube</a>`);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should turn relative links in post body to absolute urls', (done) => {
|
it('should turn relative links in post body to absolute urls', (done) => {
|
||||||
const nconf = require('nconf');
|
const nconf = require('nconf');
|
||||||
const content = '<a href="/users">test</a> <a href="youtube.com">youtube</a> some test <img src="/path/to/img"/>';
|
const content = '<a href="/users">test</a> <a href="//youtube.com">youtube</a> some test <img src="/path/to/img"/>';
|
||||||
let parsedContent = posts.relativeToAbsolute(content, posts.urlRegex);
|
let parsedContent = posts.relativeToAbsolute(content, posts.urlRegex);
|
||||||
parsedContent = posts.relativeToAbsolute(parsedContent, posts.imgRegex);
|
parsedContent = posts.relativeToAbsolute(parsedContent, posts.imgRegex);
|
||||||
assert.equal(parsedContent, `<a href="${nconf.get('base_url')}/users">test</a> <a href="//youtube.com">youtube</a> some test <img src="${nconf.get('base_url')}/path/to/img"/>`);
|
assert.equal(parsedContent, `<a href="${nconf.get('base_url')}/users">test</a> <a href="https://youtube.com/">youtube</a> some test <img src="${nconf.get('base_url')}/path/to/img"/>`);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user