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

Non-standard character set does not make 'rewrites' work #2017

Closed
3 tasks done
Xaviw opened this issue Mar 1, 2023 · 0 comments
Closed
3 tasks done

Non-standard character set does not make 'rewrites' work #2017

Xaviw opened this issue Mar 1, 2023 · 0 comments
Labels
bug Something isn't working build Related to the build system

Comments

@Xaviw
Copy link

Xaviw commented Mar 1, 2023

Describe the bug

If I set Chinese in 'rewrites', it will not work normally. Check the source code and find that the reason is that the url in 'rewritesPlugin' is encoded and cannot match the incoming value.

// src/node/plugins/rewritesPlugin.ts
export const rewritesPlugin = (config: SiteConfig): Plugin => {
  return {
    name: 'vitepress:rewrites',
    configureServer(server) {
      // dev rewrite
      server.middlewares.use((req, _res, next) => {
        // this url is encoded
        if (req.url) {
          const page = req.url
            .replace(/[?#].*$/, '')
            .slice(config.site.base.length)
          // Value in 'rewrites.inv' not encoded
          if (config.rewrites.inv[page]) {
            req.url = req.url.replace(page, config.rewrites.inv[page]!)
          }
        }
        next()
      })
    }
  }
}

Reproduction

Use Chinese as the value of the 'rewrites' configuration

Expected behavior

The value passed in can be recognized normally

System Info

System:
    OS: Windows 10 10.0.22621
    CPU: (16) x64 13th Gen Intel(R) Core(TM) i5-13400F
    Memory: 7.62 GB / 15.81 GB
  Binaries:
    Node: 18.14.1 - ~\AppData\Local\Volta\tools\image\node\18.14.1\node.EXE
    npm: 9.3.1 - ~\AppData\Local\Volta\tools\image\node\18.14.1\npm.CMD
  Browsers:
    Edge: Spartan (44.22621.1265.0), Chromium (110.0.1587.57)
    Internet Explorer: 11.0.22621.1

Additional context

No response

Validations

  • Follow our Code of Conduct
  • Read the docs.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
@Xaviw Xaviw added the bug: pending triage Maybe a bug, waiting for confirmation label Mar 1, 2023
@brc-dd brc-dd added bug Something isn't working build Related to the build system and removed bug: pending triage Maybe a bug, waiting for confirmation labels Mar 2, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working build Related to the build system
Projects
None yet
Development

No branches or pull requests

2 participants