Skip to content

Commit

Permalink
feat(v2): add relative uri support
Browse files Browse the repository at this point in the history
  • Loading branch information
moonrailgun committed Sep 15, 2020
1 parent 9bf4dfb commit 8cb594f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,14 @@ describe('validation schemas', () => {
test('URISchema', () => {
const validURL = 'https://docusaurus.io';
const doubleHash = 'https://docusaurus.io#github#/:';
const relativeUrl = '//docusaurus.io';
const invalidURL = 'invalidURL';
const urlFromIssue = 'https://riot.im/app/#/room/#ligo-public:matrix.org';

const {testFail, testOK} = createTestHelpers({schema: URISchema});
testOK(validURL);
testOK(doubleHash);
testOK(relativeUrl);
testFail(invalidURL);
testOK(urlFromIssue);
});
Expand Down
4 changes: 4 additions & 0 deletions packages/docusaurus-utils-validation/src/validationSchemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ export const URISchema = Joi.alternatives(
Joi.string().uri(),
Joi.custom((val, helpers) => {
try {
if (typeof val === 'string' && val.startsWith('//')) {
return val;
}

const url = new URL(val);
if (url) {
return val;
Expand Down

0 comments on commit 8cb594f

Please sign in to comment.