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(docusaurus-utils-validation): baseUrl + routeBasePath: allow empty string, normalized as "/" #8258

Merged
merged 6 commits into from
Dec 8, 2022

Conversation

Djunnni
Copy link
Contributor

@Djunnni Djunnni commented Oct 27, 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

some of packages, written about allow('') but it can be update by custom or default
so i use empty('') that is customed in joi

Test Plan

Test links

Deploy preview: https://deploy-preview-_____--docusaurus-2.netlify.app/

Related issues/PRs

fix #8254

#8255

@netlify
Copy link

netlify bot commented Oct 27, 2022

[V2]

Name Link
🔨 Latest commit 21a04ed
🔍 Latest deploy log https://app.netlify.com/sites/docusaurus-2/deploys/6392026ce3e4de0008abb804
😎 Deploy Preview https://deploy-preview-8258--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 27, 2022

⚡️ Lighthouse report for the deploy preview of this PR

URL Performance Accessibility Best Practices SEO PWA Report
/ 🟠 75 🟢 97 🟢 100 🟢 100 🟢 90 Report
/docs/installation 🟠 82 🟢 100 🟢 100 🟢 100 🟢 90 Report

@facebook-github-bot
Copy link
Contributor

Hi @Djunnni!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Oct 27, 2022
@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@@ -96,6 +96,9 @@ export const PathnameSchema = Joi.string()
'{{#label}} is not a valid pathname. Pathname should start with slash and not contain any domain or query string.',
);

// joi empty string not allowed by default. so using empty('') for custom use
export const RouteBasePathSchema = Joi.string().empty('').default('');
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's wait for a decision to be made in #8254 (comment)

I'd prefer to have allow('') instead of empty('') here, and not have a default value of '' => default should applied on a case by case basis.

Eventually we could use this scema for baseUrl too (rename to PathSegmentSchema?), and normalize both baseUrl + routeBasePath to have leading/trailing slashes

Copy link
Contributor Author

@Djunnni Djunnni Oct 28, 2022

Choose a reason for hiding this comment

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

When i did some of test, if use allow(''), it return ''

So i use empty('') then default('')

It gauarantee this case

joi.string().allow('').default('/') => ''
joi.string().empty('').default('').default('/') => '/'

joi.string().empty('').default('/') => '/' => this case can't gaurantee because it return undefined when i tested docusaurus-utils-validation

I found rootBasePath used '/', '', 'blogs' in this repo and then customized by default value individually

Copy link
Collaborator

Choose a reason for hiding this comment

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

You forgot I initially suggested to add the same code as baseurl: .custom((value: string) => addLeadingSlash(addTrailingSlash(value))),

Copy link
Contributor Author

@Djunnni Djunnni Oct 28, 2022

Choose a reason for hiding this comment

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

i also test this case you announced,

when i input empty string ""
joi.string().custom((value: string) => addLeadingSlash(addTrailingSlash(value))) => throw error
joi.string().allow('').custom((value: string) => addLeadingSlash(addTrailingSlash(value)) => return ''

Copy link
Contributor Author

@Djunnni Djunnni Oct 28, 2022

Choose a reason for hiding this comment

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

example

Djunnni and others added 2 commits October 28, 2022 19:53
# Conflicts:
#	packages/docusaurus-utils-validation/src/__tests__/validationSchemas.test.ts
@slorber slorber requested a review from lex111 as a code owner December 8, 2022 13:45
allow '' for baseUrl + routeBasePath
@slorber
Copy link
Collaborator

slorber commented Dec 8, 2022

Did some changes to the PR

  • baseUrl now allows '', normalized as '/', and keep its logic of adding leading/trailing slashes
  • routeBasePath now allows '', normalized as '/', and only add a leading slash

I didn't want to normalize adding a trailing slash to routeBasePath (for now) because it is likely to lead to behavior changes, particularly for parent routes such as /docs.

Maybe this is possible to normalize technically, but it would require more tests to be sure.

@slorber slorber added pr: bug fix This PR fixes a bug in a past release. to backport This PR is planned to be backported to a stable version of Docusaurus labels Dec 8, 2022
@slorber slorber changed the title fix(docusaurus-utils-validation): empty routeBasePath replace "/" instead of throwing fix(docusaurus-utils-validation): baseUrl + routeBasePath: allow empty string, normalized as "/" Dec 8, 2022
@slorber slorber merged commit e553ce7 into facebook:main Dec 8, 2022
@slorber slorber removed the to backport This PR is planned to be backported to a stable version of Docusaurus label Jan 26, 2023
This was referenced Oct 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

content plugins reject options.routeBasePath = ''
3 participants