Sanitize path segments when creating folder (#1961)
This commit is contained in:
parent
4cffd7b16e
commit
08edcd755f
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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/');
|
||||
|
|
|
|||
Loading…
Reference in New Issue