Skip to content

Relative paths are not transformed #10

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

Open
JounQin opened this issue Mar 24, 2025 · 3 comments · May be fixed by #15
Open

Relative paths are not transformed #10

JounQin opened this issue Mar 24, 2025 · 3 comments · May be fixed by #15

Comments

@JounQin
Copy link

JounQin commented Mar 24, 2025

    @@ -25,71 +25,71 @@
        {
          "column": 1,
          "endColumn": 33,
          "endLine": 17,
          "line": 17,
    -     "message": "Cannot find file `../../getting-started/next`",
    +     "message": "Cannot find file `..\..\getting-started\next`",
          "nodeType": "Program",
          "ruleId": "remark-validate-links:missing-file-missing-file",
          "severity": 1,
        },
@JounQin
Copy link
Author

JounQin commented Mar 24, 2025

I tried:

const { createSnapshotSerializer } = require('path-serializer')

const serializer = createSnapshotSerializer({
  features: {
    addDoubleQuotes: false,
    escapeDoubleQuotes: false,
  },
  replacePost: [
    {
      match: /(['"`])(\.\.([\\/]))+([\w-]+\3)+[^\\/]*\1/g,
      mark: sub => 'relative/' + sub.replaceAll('\\', '/'),
    },
  ],
})

module.exports = serializer

Well it works, with <RELATIVE_GETTING_STARTED_NEXT>, but actually I want ../../getting-started/next.

@SoonIter
Copy link
Member

SoonIter commented Apr 22, 2025

Hey, I add #13 for workaround to this feature

if you wanto serialize relative path by default in path-serializer pipeline, you can add test cases or pr to this repo, there may be some edge cases when using regular expressions for replacement.

@SoonIter SoonIter linked a pull request Apr 22, 2025 that will close this issue
@SoonIter
Copy link
Member

you can review #15

What is the source of this regular /(['"])(..([\/]))+([\w-]+\3)+[^\\/]*\1/g` expression, is it sufficiently solid?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants