Skip to content

Commit 85f4653

Browse files
committed
feat: stricter validation of heading fragments by being Case sensitive
Fixes #8 BREAKING CHANGE: Heading fragments is now Case sensitive. For example "#ExistIng-Heading" is invalid as it should be "#existing-heading".
1 parent 450cdb8 commit 85f4653

File tree

6 files changed

+19
-10
lines changed

6 files changed

+19
-10
lines changed

src/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ const customRule = {
126126

127127
fragmentsHTML.push(...idOrAnchorNameHTMLFragments)
128128

129-
if (!fragmentsHTML.includes(url.hash.toLowerCase())) {
129+
if (!fragmentsHTML.includes(url.hash)) {
130130
if (url.hash.startsWith("#L")) {
131131
const lineNumberFragmentString = getLineNumberStringFromFragment(
132132
url.hash,
@@ -157,6 +157,8 @@ const customRule = {
157157
})
158158
continue
159159
}
160+
161+
continue
160162
}
161163

162164
onError({

src/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const convertHeadingToHTMLFragment = (inlineText) => {
2828
"",
2929
)
3030
.replace(/ /gu, "-"),
31-
).toLowerCase()
31+
)
3232
)
3333
}
3434

File renamed without changes.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Valid
22

3-
[Link fragment](./awesome.md#L7)
3+
[Link fragment](./awesome.md#l7)

test/index.test.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ test("ensure the rule validates correctly", async (t) => {
4747
'"./awesome.md#not-an-id-should-be-ignored" should have a valid fragment identifier',
4848
],
4949
},
50+
{
51+
name: "should be invalid with uppercase letters in fragment (case sensitive)",
52+
fixturePath:
53+
"test/fixtures/invalid/invalid-heading-case-sensitive/invalid-heading-case-sensitive.md",
54+
errors: [
55+
'"./awesome.md#ExistIng-Heading" should have a valid fragment identifier',
56+
],
57+
},
5058
{
5159
name: "should be invalid with invalid heading with #L fragment",
5260
fixturePath:
@@ -148,7 +156,11 @@ test("ensure the rule validates correctly", async (t) => {
148156
)
149157
return result.errorDetail
150158
})
151-
assert.deepStrictEqual(errorsDetails, errors)
159+
assert.deepStrictEqual(
160+
errorsDetails,
161+
errors,
162+
`${fixturePath}: Expected errors`,
163+
)
152164
})
153165
}
154166
})
@@ -165,11 +177,6 @@ test("ensure the rule validates correctly", async (t) => {
165177
fixturePath:
166178
"test/fixtures/valid/existing-element-id-fragment/existing-element-id-fragment.md",
167179
},
168-
{
169-
name: "should be valid with an existing heading fragment (case insensitive)",
170-
fixturePath:
171-
"test/fixtures/valid/existing-heading-case-insensitive/existing-heading-case-insensitive.md",
172-
},
173180
{
174181
name: "should be valid with an existing heading fragment",
175182
fixturePath:
@@ -232,7 +239,7 @@ test("ensure the rule validates correctly", async (t) => {
232239
assert.equal(
233240
errorsDetails.length,
234241
0,
235-
`Expected no errors, got ${errorsDetails.join(", ")}`,
242+
`${fixturePath}: Expected no errors, got ${errorsDetails.join(", ")}`,
236243
)
237244
})
238245
}

0 commit comments

Comments
 (0)