Skip to content

Escaped Markdown links with spaces in them are not routed correctly #8867

Closed

Description

@VladNastase

Have you read the Contributing Guidelines on issues?

Prerequisites

Description

Links that contain spaces have to be enclosed in pointy brackets (<>) according to the CommonMark specification (see here). In Docusaurus, the links are displayed properly, but are routed to the original filename (i.e. they also keep the original file extension). A link such as [Link](<./file 1.md>) will go to https://<yourwebsitehere>/<yourpathhere>/file%201.md if onBrokenLinks is set to warn and will completely fail the build process otherwise.

Reproducible demo

https://vladnastase.github.io/docusaurus-bug/chapter1/doc

Steps to reproduce

  1. Create a file with a space in its name.
  2. Link to it using a Markdown link (do not forget to properly enclose it in pointy brackets).
  3. (Optional) Set onBrokenLinks to warn in docusaurus.config.js.
  4. Build the website and try the link, or observe the error.

Expected behavior

Build succeeds if onBrokenLinks is not set to warn, link works properly otherwise.

In the linked reproduction, links 2 and 3 should go to https://vladnastase.github.io/docusaurus-bug/chapter1/doc%202 and https://vladnastase.github.io/docusaurus-bug/chapter%202/doc1 respectively (instead of https://vladnastase.github.io/docusaurus-bug/chapter1/doc%202.md and https://vladnastase.github.io/docusaurus-bug/chapter%202/doc1.md)

Actual behavior

Build fails if onBrokenLinks is not set to warn, links don't work properly (they keep the original file extension).

Your environment

Self-service

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

Activity

  1. added
    bug
    status: needs triage
    on Apr 4, 2023
  2. removed
    status: needs triage
    on Apr 6, 2023
  3. slorber commented on Apr 6, 2023

    @slorber
    Collaborator

    Thanks, didn't know about this markdown link escaping rule in CommonMark.

    Runnable repro: https://stackblitz.com/~/github.com/VladNastase/docusaurus-bug


    Note repro shows:

    # Bug example
    
    [This](./doc3.md) link works.
    
    [This](<./doc 2.md>) doesn't work.
    
    [This](<../chapter 2/doc1.md>) also doesn't work.

    CleanShot 2023-04-06 at 19 28 00@2x

    To complete your repro:

    [This](/doc 2.md) does not work
    
    [This](./doc%202.md) works
    

    I think we can consider this a valid bug, even though the linking to .md extensions is something proprietary, we should be able to use spaces in such links.

    Using %20 instead of space is a good temporary workaround

  4. added
    good first issue
    on Apr 6, 2023
  5. Himmu5 commented on Apr 9, 2023

    @Himmu5

    Subject: Request to work on Issue #8867
    Hi there,

    My name is Himanshu Chauhan.

    I noticed that there's an open issue [#8867] that I think I can help with. It's about to solve this bug. I'm interested in working on this issue and contributing to the project.

    Before I start working on it, I wanted to check with you to see if it's okay for me to work on this issue. If it is, could you provide me with any guidance on how to proceed with the issue? I'm eager to learn more about the project and contribute to it in any way that I can.

    Thank you for your time and consideration.

    Best regards,
    Himanshu Chauhan

  6. morsko1 commented on Apr 11, 2023

    @morsko1
    Contributor

    The problem is that existing regex for Markdown links doesn't match filenames that contain whitespaces and wrapped with <>.
    I have created PR #8874 with modified regex.
    I tested these changes locally with files and folders that contain spaces and looks like it fixes the issue.
    Here is the link to updated regex where you can check how it matches filenames with or without spaces.

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

    buggood first issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions