fix(v2): allow relative URLs in URISchema #3449

This commit is contained in:
Tom Milligan 2020-09-29 17:34:39 +01:00 committed by GitHub
parent 55cd7a7b5a
commit fe78cbeff5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 3 deletions

View file

@ -60,4 +60,4 @@ exports[`validation schemas RemarkPluginsSchema: for value=false 1`] = `"\\"valu
exports[`validation schemas RemarkPluginsSchema: for value=null 1`] = `"\\"value\\" must be an array"`;
exports[`validation schemas URISchema: for value="invalidURL" 1`] = `"\\"value\\" does not match any of the allowed types"`;
exports[`validation schemas URISchema: for value="spaces are invalid in a URL" 1`] = `"\\"value\\" does not match any of the allowed types"`;

View file

@ -111,12 +111,16 @@ describe('validation schemas', () => {
test('URISchema', () => {
const validURL = 'https://docusaurus.io';
const doubleHash = 'https://docusaurus.io#github#/:';
const invalidURL = 'invalidURL';
const invalidURL = 'spaces are invalid in a URL';
const relativeURL = 'relativeURL';
const relativeURLWithParent = '../relativeURLWithParent';
const urlFromIssue = 'https://riot.im/app/#/room/#ligo-public:matrix.org';
const {testFail, testOK} = createTestHelpers({schema: URISchema});
testOK(validURL);
testOK(doubleHash);
testFail(invalidURL);
testOK(relativeURL);
testOK(relativeURLWithParent);
testOK(urlFromIssue);
});
});

View file

@ -26,7 +26,7 @@ export const RehypePluginsSchema = MarkdownPluginsSchema;
export const AdmonitionsSchema = Joi.object().default({});
export const URISchema = Joi.alternatives(
Joi.string().uri(),
Joi.string().uri({allowRelative: true}),
Joi.custom((val, helpers) => {
try {
const url = new URL(val);