mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-10 23:57:22 +02:00
fix(v2): allow relative URLs in URISchema #3449
This commit is contained in:
parent
55cd7a7b5a
commit
fe78cbeff5
3 changed files with 7 additions and 3 deletions
|
@ -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"`;
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue