mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-10 15:47:23 +02:00
fix(v2): relax URI validation (#3227)
* relax URI validation * add regex * add test * fix linting error * fix formatting * use URL rather than regex
This commit is contained in:
parent
fe281a8ebe
commit
181a6174c7
9 changed files with 44 additions and 7 deletions
|
@ -59,3 +59,5 @@ exports[`validation schemas RemarkPluginsSchema: for value=3 1`] = `"\\"value\\"
|
|||
exports[`validation schemas RemarkPluginsSchema: for value=false 1`] = `"\\"value\\" must be an array"`;
|
||||
|
||||
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"`;
|
||||
|
|
|
@ -12,6 +12,7 @@ import {
|
|||
RehypePluginsSchema,
|
||||
RemarkPluginsSchema,
|
||||
PluginIdSchema,
|
||||
URISchema,
|
||||
} from '../validationSchemas';
|
||||
|
||||
function createTestHelpers({
|
||||
|
@ -106,4 +107,16 @@ describe('validation schemas', () => {
|
|||
test('RehypePluginsSchema', () => {
|
||||
testMarkdownPluginSchemas(RehypePluginsSchema);
|
||||
});
|
||||
|
||||
test('URISchema', () => {
|
||||
const validURL = 'https://docusaurus.io';
|
||||
const doubleHash = 'https://docusaurus.io#github#/:';
|
||||
const invalidURL = 'invalidURL';
|
||||
const urlFromIssue = 'https://riot.im/app/#/room/#ligo-public:matrix.org';
|
||||
const {testFail, testOK} = createTestHelpers({schema: URISchema});
|
||||
testOK(validURL);
|
||||
testOK(doubleHash);
|
||||
testFail(invalidURL);
|
||||
testOK(urlFromIssue);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -25,3 +25,19 @@ export const RemarkPluginsSchema = MarkdownPluginsSchema;
|
|||
export const RehypePluginsSchema = MarkdownPluginsSchema;
|
||||
|
||||
export const AdmonitionsSchema = Joi.object().default({});
|
||||
|
||||
export const URISchema = Joi.alternatives(
|
||||
Joi.string().uri(),
|
||||
Joi.custom((val, helpers) => {
|
||||
try {
|
||||
const url = new URL(val);
|
||||
if (url) {
|
||||
return val;
|
||||
} else {
|
||||
return helpers.error('any.invalid');
|
||||
}
|
||||
} catch {
|
||||
return helpers.error('any.invalid');
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue