vuejs / vitepress

Vite & Vue powered static site generator.
https://vitepress.dev
MIT License
13.25k stars 2.14k forks source link

1.4 Broke rewrites #4261

Closed jasonkuhrt closed 1 month ago

jasonkuhrt commented 1 month ago

Describe the bug

I use these rewrites in my Vitepress config:

rewrites: {
    ':section/{:_(\\d+_)}?:one/{:_(\\d+_)}?:two/{:_(\\d+_)}?:three'   : ':section/:one/:two/:three',
    ':section/{:_(\\d+_)}?:one/{:_(\\d+_)}?:two'                      : ':section/:one/:two',
    ':section/{:_(\\d+_)}?:one'                                       : ':section/:one'
  },

Reproduction

I have a failing case right now on this PR, example build failure: https://github.com/jasonkuhrt/graffle/actions/runs/11219992004/job/31187185529?pr=1168.

CleanShot 2024-10-09 at 10 23 25@2x

Expected behavior

I expected that a minor release of Vitepress would not break the config.

System Info

System:
    OS: macOS 15.0
    CPU: (8) arm64 Apple M1 Pro
    Memory: 78.25 MB / 32.00 GB
    Shell: 3.5.0 - /opt/homebrew/bin/fish
  Binaries:
    Node: 22.7.0 - ~/Library/pnpm/node
    npm: 10.8.2 - ~/Library/pnpm/npm
    pnpm: 9.12.1 - /opt/homebrew/bin/pnpm
  Browsers:
    Brave Browser: 114.1.52.122
    Chrome: 129.0.6668.91
    Safari: 18.0
  npmPackages:
    vitepress: ^1.3.4 => 1.3.4 


### Additional context

_No response_

### Validations

- [X] Check if you're on the [latest VitePress version](https://github.com/vuejs/vitepress/releases/latest).
- [X] Follow our [Code of Conduct](https://vuejs.org/about/coc.html)
- [X] Read the [docs](https://vitepress.dev).
- [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
brc-dd commented 1 month ago

path-to-regexp had a vulnerability. Their fix broke your rewrite patterns somehow - https://github.com/pillarjs/path-to-regexp/pull/324

This likely won't be fixed at source as it's a vulnerability patch not exactly a regression. You can use pnpm.overrides to lock it to ~6.2 (not recommended in long term). Or update your pattern to work with newer versions.

yshrsmz commented 1 month ago

I had a similar problem.

I had this rewrites config

rewrites: {
 'posts/:skipped/:year-:month-:day-:slug.md': ':year/:month/:day/:slug/index.md',
}

and now /posts/2018/2018-03-27-settingup-github-slack.md becomes /2018-03-27/settingup/github/slack/index.html.

It was once rewrited as /2018/03/27/settingup-github-slack/index.html.

Edit: changing the pattern to posts/:skipped/:year-:month-:day-:slug(.*).md fixed the issue for me.

jasonkuhrt commented 1 month ago

I'm not sure this library is the best match for Vitepress. The security issue in question is not relevant for a static site generator is it?

May I ask that you add the option for a function to be passed to rewrite paths? I've already struggled to use the existing approach and not sure how to fix it now. The version Vitepress uses is not the latest, its docs are not what's currently on the latest readme but rather I have to find older commits. All of this for me is just extra work versus having a function I could just implement what I want.

Would that be doable or does the currently declarative approach have deeply dependent internals?

brc-dd commented 1 month ago

Yeah we can support passing a function 👀

brc-dd commented 1 month ago

Will be out in next version.

jasonkuhrt commented 1 month ago

@brc-dd thanks that's great to hear! Looking forward to it.

brc-dd commented 1 month ago

Released. Should I close this issue? I don't think we can do much about path-to-regexp breaking edge cases from vitepress' side. And I also updated the docs to link to it's v6 version. We won't update it to v8 till our next major 👀

jasonkuhrt commented 1 month ago

Yep sounds good let's close!