mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-12 08:37:25 +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 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', () => {
|
test('URISchema', () => {
|
||||||
const validURL = 'https://docusaurus.io';
|
const validURL = 'https://docusaurus.io';
|
||||||
const doubleHash = 'https://docusaurus.io#github#/:';
|
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 urlFromIssue = 'https://riot.im/app/#/room/#ligo-public:matrix.org';
|
||||||
const {testFail, testOK} = createTestHelpers({schema: URISchema});
|
const {testFail, testOK} = createTestHelpers({schema: URISchema});
|
||||||
testOK(validURL);
|
testOK(validURL);
|
||||||
testOK(doubleHash);
|
testOK(doubleHash);
|
||||||
testFail(invalidURL);
|
testFail(invalidURL);
|
||||||
|
testOK(relativeURL);
|
||||||
|
testOK(relativeURLWithParent);
|
||||||
testOK(urlFromIssue);
|
testOK(urlFromIssue);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -26,7 +26,7 @@ export const RehypePluginsSchema = MarkdownPluginsSchema;
|
||||||
export const AdmonitionsSchema = Joi.object().default({});
|
export const AdmonitionsSchema = Joi.object().default({});
|
||||||
|
|
||||||
export const URISchema = Joi.alternatives(
|
export const URISchema = Joi.alternatives(
|
||||||
Joi.string().uri(),
|
Joi.string().uri({allowRelative: true}),
|
||||||
Joi.custom((val, helpers) => {
|
Joi.custom((val, helpers) => {
|
||||||
try {
|
try {
|
||||||
const url = new URL(val);
|
const url = new URL(val);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue