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(core): throw error for invalid URL in config file #8192

Merged
merged 2 commits into from Oct 13, 2022

Conversation

forgeRW
Copy link
Contributor

@forgeRW forgeRW commented Oct 8, 2022

Pre-flight checklist

  • I have read the Contributing Guidelines on pull requests.
  • If this is a code change: I have written unit tests and/or added dogfooding pages to fully verify the new behavior.
  • If this is a new API or substantial change: the PR has an accompanying issue (closes #0000) and the maintainers have approved on my working plan.

Motivation

Currently, a warning is displayed when the URL contains a sub-path but as mentioned at the end of #8159, it makes more sense to display an error. So, I updated the code to display an error instead of a warning.

Test Plan

Test links

I updated unit tests to verify my code.

Related issues/PRs

Related to #8159 and #8116

    * fix: throw error for site URL in sub-path format

    * Also update unit tests to check error is thrown
@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Oct 8, 2022
@netlify
Copy link

netlify bot commented Oct 8, 2022

[V2]

Built without sensitive environment variables

Name Link
🔨 Latest commit 66fee93
🔍 Latest deploy log https://app.netlify.com/sites/docusaurus-2/deploys/63477b72de189b0008b32b98
😎 Deploy Preview https://deploy-preview-8192--docusaurus-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@github-actions
Copy link

github-actions bot commented Oct 8, 2022

⚡️ Lighthouse report for the deploy preview of this PR

URL Performance Accessibility Best Practices SEO PWA Report
/ 🟠 52 🟢 98 🟢 100 🟢 100 🟠 80 Report
/docs/installation 🟠 80 🟢 100 🟢 100 🟢 100 🟢 90 Report

Copy link
Collaborator

@slorber slorber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks 👍

Not ready to be merged yet

Comment on lines 118 to 126
expect(() =>
normalizeConfig({
// This shouldn't happen
url: 'https://mysite.com/foo/',
}).url,
).toBe('https://mysite.com/foo');

expect(consoleMock.mock.calls[0][0]).toMatchInlineSnapshot(
`"[WARNING] Docusaurus config validation warning. Field "url": The url is not supposed to contain a sub-path like '/foo/'. Please use the baseUrl field for sub-paths."`,
);
}),
).toThrowErrorMatchingInlineSnapshot(`
"The url is not supposed to contain a sub-path like "". Please use the baseUrl field for sub-paths.
"
`);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure we need this anymore, at least not in this test group, because here it's not testing URL normalization but URL rejection so this feels weird

helpers.warn('docusaurus.configValidationWarning', {
warningMessage: `The url is not supposed to contain a sub-path like '${pathname}'. Please use the baseUrl field for sub-paths.`,
});
return helpers.error('docusaurus.configValidationWarning');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should use configValidationWarning for something that is an error. Also pathname used to be interpolated but it's not anymore

Unfortunately I can't really guide you to the correct solution: Joi is really a pain to do anything basic such as returning a custom error message 😅

@Josh-Cena Josh-Cena changed the title fix(core): throw error for invalid URL in config file (#8116) fix(core): throw error for invalid URL in config file Oct 12, 2022
…acebook#8192)

    * fix: throw custom error for site URL with sub-path

    * Also update unit test to check error is thrown
@slorber slorber added the pr: bug fix This PR fixes a bug in a past release. label Oct 13, 2022
@slorber
Copy link
Collaborator

slorber commented Oct 13, 2022

LGTM thanks 👍

@slorber slorber merged commit 2372335 into facebook:main Oct 13, 2022
@slorber slorber added the to backport This PR is planned to be backported to a stable version of Docusaurus label Oct 13, 2022
@slorber slorber added backported This PR has been backported to a stable version of Docusaurus and removed to backport This PR is planned to be backported to a stable version of Docusaurus labels Nov 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backported This PR has been backported to a stable version of Docusaurus CLA Signed Signed Facebook CLA pr: bug fix This PR fixes a bug in a past release.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants