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

test(v2): add protocol relative uri validation test #3453

Merged
merged 3 commits into from
Sep 29, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -111,11 +111,14 @@ describe('validation schemas', () => {
test('URISchema', () => {
const validURL = 'https://docusaurus.io';
const doubleHash = 'https://docusaurus.io#github#/:';
const relativeUrl = '//docusaurus.io';
const invalidURL = 'invalidURL';
const urlFromIssue = 'https://riot.im/app/#/room/#ligo-public:matrix.org';

const {testFail, testOK} = createTestHelpers({schema: URISchema});
testOK(validURL);
testOK(doubleHash);
testOK(relativeUrl);
testFail(invalidURL);
testOK(urlFromIssue);
});
Expand Down
4 changes: 4 additions & 0 deletions packages/docusaurus-utils-validation/src/validationSchemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ export const URISchema = Joi.alternatives(
Joi.string().uri(),
Joi.custom((val, helpers) => {
try {
if (typeof val === 'string' && val.startsWith('//')) {
return val;
}

const url = new URL(val);
if (url) {
return val;
Expand Down