Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Sep 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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"`;
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down