Skip to content

Commit 4b6f66d

Browse files
committed
fix: prevent invalid validation issues in files with a path containing special characters
1 parent 3342331 commit 4b6f66d

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

packages/starlight-links-validator/libs/remark.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ function normalizeFilePath(filePath?: string) {
130130
.replace(/\.\w+$/, '')
131131
.replace(/index$/, '')
132132
.replace(/\/?$/, '/')
133+
.split('/')
134+
.map((segment) => slug(segment))
135+
.join('/')
133136
}
134137

135138
function isMdxIdAttribute(attribute: MdxJsxAttribute | MdxJsxExpressionAttribute): attribute is MdxIdAttribute {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
title: Namespace Test
3+
---
4+
5+
## Some content
6+
7+
[A link](#some-other-content)
8+
[Another link](/guides/namespacetest/#another-content)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
title: Namespace Test
3+
---
4+
5+
## Some content
6+
7+
[A link](#some-content)
8+
[Another link](/guides/namespacetest/#some-content)

packages/starlight-links-validator/tests/validation.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ test('should build with valid links', async () => {
1111
})
1212

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

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

2121
expect(error).toMatch(
2222
new RegExp(`▶ test/
@@ -37,5 +37,11 @@ test('should not build with invalid links', async () => {
3737
├─ /unknown
3838
└─ #anotherBlock`)
3939
)
40+
41+
expect(error).toMatch(
42+
new RegExp(`▶ guides/namespacetest/
43+
├─ #some-other-content
44+
└─ /guides/namespacetest/#another-content`)
45+
)
4046
}
4147
})

0 commit comments

Comments
 (0)