Skip to content

Commit

Permalink
fix: prevent invalid validation issues in files with a path containin…
Browse files Browse the repository at this point in the history
…g special characters
  • Loading branch information
HiDeoo committed Aug 16, 2023
1 parent 3342331 commit 4b6f66d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
3 changes: 3 additions & 0 deletions packages/starlight-links-validator/libs/remark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ function normalizeFilePath(filePath?: string) {
.replace(/\.\w+$/, '')
.replace(/index$/, '')
.replace(/\/?$/, '/')
.split('/')
.map((segment) => slug(segment))
.join('/')
}

function isMdxIdAttribute(attribute: MdxJsxAttribute | MdxJsxExpressionAttribute): attribute is MdxIdAttribute {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
title: Namespace Test
---

## Some content

[A link](#some-other-content)
[Another link](/guides/namespacetest/#another-content)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
title: Namespace Test
---

## Some content

[A link](#some-content)
[Another link](/guides/namespacetest/#some-content)
10 changes: 8 additions & 2 deletions packages/starlight-links-validator/tests/validation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ test('should build with valid links', async () => {
})

test('should not build with invalid links', async () => {
expect.assertions(3)
expect.assertions(4)

try {
await loadFixture('with-invalid-links')
} catch (error) {
expect(error).toMatch(/Found 12 invalid links in 2 files./)
expect(error).toMatch(/Found 14 invalid links in 3 files./)

expect(error).toMatch(
new RegExp(`▶ test/
Expand All @@ -37,5 +37,11 @@ test('should not build with invalid links', async () => {
├─ /unknown
└─ #anotherBlock`)
)

expect(error).toMatch(
new RegExp(`▶ guides/namespacetest/
├─ #some-other-content
└─ /guides/namespacetest/#another-content`)
)
}
})

0 comments on commit 4b6f66d

Please sign in to comment.