From 0e466122e2968d1c6f8295d94e328b0d5f1e49fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Fri, 3 Jun 2016 11:20:53 +0300 Subject: [PATCH] closes #4717 --- src/posts/parse.js | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/posts/parse.js b/src/posts/parse.js index 6381e066ed..087146e77d 100644 --- a/src/posts/parse.js +++ b/src/posts/parse.js @@ -1,7 +1,8 @@ 'use strict'; -var nconf = require('nconf'), - url = require('url'); +var nconf = require('nconf'); +var url = require('url'); +var winston = require('winston'); var cache = require('./cache'); var plugins = require('../plugins'); @@ -50,21 +51,24 @@ module.exports = function(Posts) { // Turns relative links in post body to absolute urls var parsed, current, absolute; - while ((current=urlRegex.exec(content)) !== null) { + while ((current = urlRegex.exec(content)) !== null) { if (current[1]) { - parsed = url.parse(current[1]); + try { + parsed = url.parse(current[1]); + if (!parsed.protocol) { + if (current[1].startsWith('/')) { + // Internal link + absolute = nconf.get('url') + current[1]; + } else { + // External link + absolute = '//' + current[1]; + } - if (!parsed.protocol) { - if (current[1].startsWith('/')) { - // Internal link - absolute = nconf.get('url') + current[1]; - } else { - // External link - absolute = '//' + current[1]; + content = content.slice(0, current.index + 6) + absolute + content.slice(current.index + 6 + current[1].length); } - - content = content.slice(0, current.index + 6) + absolute + content.slice(current.index + 6 + current[1].length); - } + } catch(err) { + winston.verbose(err.messsage); + } } }