Sanitize path segments when creating folder (#1961)

This commit is contained in:
Ryan Siddle 2018-05-13 08:17:42 +01:00 committed by Peter Hedenskog
parent 4cffd7b16e
commit 08edcd755f
2 changed files with 9 additions and 0 deletions

View File

@ -12,6 +12,10 @@ module.exports = function pathFromRootToPageDir(url) {
pathSegments.unshift('pages');
pathSegments.forEach(function(segment, index) {
pathSegments[index] = segment.replace(/[^-a-z0-9_.]/gi, '-');
});
if (!isEmpty(parsedUrl.search)) {
const md5 = crypto.createHash('md5'),
hash = md5

View File

@ -14,6 +14,11 @@ describe('pathFromRootToPageDir', function() {
expect(path).to.equal('pages/www.foo.bar/x/y/z.html/');
});
it('should create path from url with sanitized characters', function() {
const path = pathFromRootToPageDir('http://www.foo.bar/x/y/z:200.html');
expect(path).to.equal('pages/www.foo.bar/x/y/z-200.html/');
});
it('should create path from url with query string', function() {
const path = pathFromRootToPageDir('http://www.foo.bar/x/y/z?foo=bar');
expect(path).to.equal('pages/www.foo.bar/x/y/z/query-115ffe20/');