mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-27 22:49:56 -05:00
Merge pull request #4887 from jaswilli/issue-4886
Fix error in generating absolute URLs for RSS
This commit is contained in:
commit
6005bc732d
1 changed files with 42 additions and 2 deletions
|
@ -513,11 +513,51 @@ frontendControllers = {
|
||||||
// convert relative resource urls to absolute
|
// convert relative resource urls to absolute
|
||||||
['href', 'src'].forEach(function (attributeName) {
|
['href', 'src'].forEach(function (attributeName) {
|
||||||
htmlContent('[' + attributeName + ']').each(function (ix, el) {
|
htmlContent('[' + attributeName + ']').each(function (ix, el) {
|
||||||
|
var baseUrl,
|
||||||
|
attributeValue,
|
||||||
|
parsed;
|
||||||
|
|
||||||
el = htmlContent(el);
|
el = htmlContent(el);
|
||||||
|
|
||||||
var attributeValue = el.attr(attributeName);
|
attributeValue = el.attr(attributeName);
|
||||||
attributeValue = url.resolve(siteUrl, attributeValue);
|
|
||||||
|
|
||||||
|
// if URL is absolute move on to the next element
|
||||||
|
try {
|
||||||
|
parsed = url.parse(attributeValue);
|
||||||
|
|
||||||
|
if (parsed.protocol) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// compose an absolute URL
|
||||||
|
|
||||||
|
// if the relative URL begins with a '/' use the blog URL (including sub-directory)
|
||||||
|
// as the base URL, otherwise use the post's URL.
|
||||||
|
baseUrl = attributeValue[0] === '/' ? siteUrl : item.url;
|
||||||
|
|
||||||
|
// prevent double slashes
|
||||||
|
if (baseUrl.slice(-1) === '/' && attributeValue[0] === '/') {
|
||||||
|
attributeValue = attributeValue.substr(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// make sure URL has a trailing slash
|
||||||
|
try {
|
||||||
|
parsed = url.parse(attributeValue);
|
||||||
|
|
||||||
|
if (parsed.pathname && parsed.pathname.slice(-1) !== '/') {
|
||||||
|
parsed.pathname += '/';
|
||||||
|
|
||||||
|
attributeValue = url.format(parsed);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
// if the URL we've built cannot be parsed, fall back to the unprocessed URL
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
attributeValue = baseUrl + attributeValue;
|
||||||
el.attr(attributeName, attributeValue);
|
el.attr(attributeName, attributeValue);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue