add isValidPathname

This commit is contained in:
slorber 2020-06-03 15:40:10 +02:00
parent 4e8b361d00
commit da8ccd0419
2 changed files with 29 additions and 0 deletions

View file

@ -18,6 +18,7 @@ import {
objectWithKeySorted,
aliasedSitePath,
createExcerpt,
isValidPathname,
} from '../index';
describe('load utils', () => {
@ -363,4 +364,20 @@ describe('load utils', () => {
expect(createExcerpt(testCase.input)).toEqual(testCase.output);
});
});
test('isValidPathname', () => {
expect(isValidPathname('/')).toBe(true);
expect(isValidPathname('/hey')).toBe(true);
expect(isValidPathname('/hey/ho')).toBe(true);
expect(isValidPathname('/hey/ho/')).toBe(true);
expect(isValidPathname('/hey/h%C3%B4/')).toBe(true);
expect(isValidPathname('/hey///ho///')).toBe(true); // Unexpected but valid
//
expect(isValidPathname('')).toBe(false);
expect(isValidPathname('hey')).toBe(false);
expect(isValidPathname('/hey/hô')).toBe(false);
expect(isValidPathname('/hey?qs=ho')).toBe(false);
expect(isValidPathname('https://fb.com/hey')).toBe(false);
expect(isValidPathname('//hey')).toBe(false);
});
});