mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-29 13:52:10 +03:00
🐛 Fixed subdirectory handling and deduplication
no issue Ghost's relative->absolute handling is a little strange when the rootUrl includes a subdirectory. Root-relative paths such as /content/image.jpg are actually treated as subdirectory-relative. This means that it's possible to migrate from a root config to a subdirectory config without migrating data in the database, _however_ that means that the database will now have a mix of path styles (/content/image.png and /subdir/content/image.png). To handle this when all root-relative paths are treated as subdir-relative we have to rely on subdirectory deduplication. - updates tests to reflect correct subdirectory handling according to the above rules - fixes missing subdirectories when root urls contain subdirectories but relative paths do not - fixes subdirectory deduplication when the supplied url/path does not have a trailing slash but matches the root url's subdirectory
This commit is contained in:
parent
86343f028b
commit
523278b295
@ -127,5 +127,13 @@ describe('utils: deduplicateSubdirectory()', function () {
|
|||||||
deduplicateSubdirectory(path, 'http://example.blog/blog/subdir/')
|
deduplicateSubdirectory(path, 'http://example.blog/blog/subdir/')
|
||||||
.should.eql('/blog/blog/file.png?test=true#testing', 'with root trailing-slash');
|
.should.eql('/blog/blog/file.png?test=true#testing', 'with root trailing-slash');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('deduplicates path with no trailing slash that matches subdir', function () {
|
||||||
|
deduplicateSubdirectory('/blog/blog', 'http://example.com/blog')
|
||||||
|
.should.equal('/blog/', 'without root trailing-slash');
|
||||||
|
|
||||||
|
deduplicateSubdirectory('/blog/blog', 'http://example.com/blog/')
|
||||||
|
.should.equal('/blog/', 'with root trailing-slash');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -23,7 +23,7 @@ const deduplicateSubdirectory = function deduplicateSubdirectory(url, rootUrl) {
|
|||||||
const subdir = parsedRoot.pathname.replace(/(^\/|\/$)+/g, '');
|
const subdir = parsedRoot.pathname.replace(/(^\/|\/$)+/g, '');
|
||||||
// we can have subdirs that match TLDs so we need to restrict matches to
|
// we can have subdirs that match TLDs so we need to restrict matches to
|
||||||
// duplicates that start with a / or the beginning of the url
|
// duplicates that start with a / or the beginning of the url
|
||||||
const subdirRegex = new RegExp(`(^|/)${subdir}/${subdir}/`);
|
const subdirRegex = new RegExp(`(^|/)${subdir}/${subdir}(/|$)`);
|
||||||
|
|
||||||
return url.replace(subdirRegex, `$1${subdir}/`);
|
return url.replace(subdirRegex, `$1${subdir}/`);
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user