Skip to content

Broken link check is case-insensitive #9057

Closed

Description

@birdofpreyru

Have you read the Contributing Guidelines on issues?

Prerequisites

Description

Hey. Not sure, is it a bug, or a feature, but currently the broken links check by Docusaurus is case-insensitive. It would be case-sensitive if routes objects used for the match had sensitive: true flags, but currently they don't have this field. The case-sensitivity matters if generated documentation is served from a service, like Google.Cloud Storage, which treats file URLs in case-sensitive manner.

Reproducible demo

No response

Steps to reproduce

N/A

Expected behavior

N/A

Actual behavior

N/A

Your environment

  • Public source code:
  • Public site URL:
  • Docusaurus version used:
  • Environment name and version (e.g. Chrome 89, Node.js 16.4):
  • Operating system and version (e.g. Ubuntu 20.04.2 LTS):

Self-service

  • I'd be willing to fix this bug myself.

Activity

  1. added
    bug
    status: needs triage
    on Jun 11, 2023
  2. Josh-Cena commented on Jun 12, 2023

    @Josh-Cena
    Collaborator

    Are you using Mac/Windows? Our route matching algorithm uses the file system API to decide if the respective file exists, and Mac/Windows is case-insensitive. You would get case-sensitive behavior on Linux (which I would assume most deployment systems are). I don't know if we want to add additional complexity of determining whether your file server is case-sensitive because most servers seem to be case-insensitive.

  3. birdofpreyru commented on Jun 12, 2023

    @birdofpreyru
    Author

    @Josh-Cena I am using Ubuntu 22.04.2 LTS, and having this issue, so I don't think matchRoutes() from react-router-config relies on the file system API to match; I guess it just directly compares given URL strings, and does not care if corresponding files exist on the disk.

  4. removed
    status: needs triage
    on Jun 14, 2023
  5. added this to the 3.0.0 milestone on Jun 14, 2023
  6. slorber commented on Jun 14, 2023

    @slorber
    Collaborator

    Makes sense to me 👍

    We should match sensitively by default, but this might prevent existing sites from building so it's a breaking change.

    I will try to do the change for v3 and provide a secret env variable in case it's annoying for some users (also useful until their bad links get fixed).

    Eventually, we can add an option to decide how the broken link checker should match, but let's wait first to see if users complain and if this is really needed.

  7. slorber commented on Jun 15, 2023

    @slorber
    Collaborator

    Note to myself

    lost 1h investigating this and it's a bit more complicated.


    filterExistingFileLinks filters the link ahead of the matchRoutes comparison call.

    And this function is case-insensitive on case-insensitive filesystems:

    async function isExistingFile(filePath: string) {
      try {
        return (await fs.stat(filePath)).isFile();
      } catch {
        return false;
      }
    }

    I'm not sure of the benefits of keeping filterExistingFileLinks anyway, it's kind of a useless double protection for regular SPA routes, so I'm in favor of removing it. But maybe some parts of it should be kept?

    Need to study this more in-depth, but now is not the ideal time.

  8. caramelmelmel commented on Sep 15, 2023

    @caramelmelmel

    Hi @slorber will this be continued?

  9. slorber commented on Sep 18, 2023

    @slorber
    Collaborator

    Need to study this more in-depth, but now is not the ideal time.

    Until v3 is released this issue is not a short term goal to fix

  10. slorber commented on Feb 13, 2024

    @slorber
    Collaborator

    As part of the v3.1 broken anchor checker:

    We removed the weird filterExistingFileLinks function I mentioned above, because it prevented Docusaurus from detecting actual broken links.

    Now the broken link checking is case sensitive, see playground:
    https://stackblitz.com/edit/github-efpqba?file=docusaurus.config.ts

    CleanShot 2024-02-13 at 13 32 06

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions