mirror of
https://github.com/serokell/xrefcheck.git
synced 2024-09-11 21:47:20 +03:00
[#120] Fix bug with ignoring checks for relative anchors
Problem: When a file contains a reference to another file, and that reference contains an anchor, that anchor is not checked. Solution: Normalise relative anchor links before check.
This commit is contained in:
parent
fd147e6856
commit
36a1da6473
@ -11,3 +11,7 @@ License: Unlicense
|
|||||||
Files: tests/configs/github-config.yaml
|
Files: tests/configs/github-config.yaml
|
||||||
Copyright: 2019-2021 Serokell <https://serokell.io>
|
Copyright: 2019-2021 Serokell <https://serokell.io>
|
||||||
License: Unlicense
|
License: Unlicense
|
||||||
|
|
||||||
|
Files: tests/golden/**/*.gold
|
||||||
|
Copyright: 2022 Serokell <https://serokell.io>
|
||||||
|
License: Unlicense
|
||||||
|
@ -33,6 +33,8 @@ Unreleased
|
|||||||
+ Add support for the `id` attribute in anchors.
|
+ Add support for the `id` attribute in anchors.
|
||||||
* [#116](https://github.com/serokell/xrefcheck/pull/116)
|
* [#116](https://github.com/serokell/xrefcheck/pull/116)
|
||||||
+ Allow certain reserved characters to be present in the query strings of the URLs.
|
+ Allow certain reserved characters to be present in the query strings of the URLs.
|
||||||
|
* [#130](https://github.com/serokell/xrefcheck/pull/130)
|
||||||
|
+ Fixed bug with ignoring checks for relative anchors.
|
||||||
|
|
||||||
0.2.1
|
0.2.1
|
||||||
==========
|
==========
|
||||||
|
@ -308,7 +308,7 @@ verifyReference
|
|||||||
then case locType of
|
then case locType of
|
||||||
LocalLoc -> checkRef rAnchor fileWithReference
|
LocalLoc -> checkRef rAnchor fileWithReference
|
||||||
RelativeLoc -> checkRef rAnchor
|
RelativeLoc -> checkRef rAnchor
|
||||||
(takeDirectory fileWithReference
|
(normalise $ takeDirectory fileWithReference
|
||||||
</> toString (canonizeLocalRef rLink))
|
</> toString (canonizeLocalRef rLink))
|
||||||
AbsoluteLoc -> checkRef rAnchor (root <> toString rLink)
|
AbsoluteLoc -> checkRef rAnchor (root <> toString rLink)
|
||||||
ExternalLoc -> checkExternalResource config rLink
|
ExternalLoc -> checkExternalResource config rLink
|
||||||
|
21
tests/golden/check-anchors/check-anchors.bats
Normal file
21
tests/golden/check-anchors/check-anchors.bats
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
#!/usr/bin/env bats
|
||||||
|
|
||||||
|
# SPDX-FileCopyrightText: 2022 Serokell <https://serokell.io>
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: MPL-2.0
|
||||||
|
|
||||||
|
load '../helpers/bats-support/load'
|
||||||
|
load '../helpers/bats-assert/load'
|
||||||
|
load '../helpers'
|
||||||
|
|
||||||
|
|
||||||
|
@test "Relative anchor, check error report" {
|
||||||
|
xrefcheck | prepare > /tmp/check-anchors.test || true
|
||||||
|
|
||||||
|
diff /tmp/check-anchors.test expected.gold \
|
||||||
|
--ignore-space-change \
|
||||||
|
--ignore-blank-lines \
|
||||||
|
--new-file # treat absent files as empty
|
||||||
|
|
||||||
|
rm /tmp/check-anchors.test
|
||||||
|
}
|
7
tests/golden/check-anchors/check-relative-anchor.md
Normal file
7
tests/golden/check-anchors/check-relative-anchor.md
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<!--
|
||||||
|
- SPDX-FileCopyrightText: 2022 Serokell <https://serokell.io>
|
||||||
|
-
|
||||||
|
- SPDX-License-Identifier: MPL-2.0
|
||||||
|
-->
|
||||||
|
|
||||||
|
[no-anchor](no-anchor.md#invalid-anchor)
|
12
tests/golden/check-anchors/expected.gold
Normal file
12
tests/golden/check-anchors/expected.gold
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
=== Invalid references found ===
|
||||||
|
|
||||||
|
➥ In file check-relative-anchor.md
|
||||||
|
bad reference (relative) at src:7:1-40:
|
||||||
|
- text: "no-anchor"
|
||||||
|
- link: no-anchor.md
|
||||||
|
- anchor: invalid-anchor
|
||||||
|
|
||||||
|
⛀ Anchor 'invalid-anchor' is not present
|
||||||
|
|
||||||
|
|
||||||
|
Invalid references dumped, 1 in total.
|
7
tests/golden/check-anchors/no-anchor.md
Normal file
7
tests/golden/check-anchors/no-anchor.md
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<!--
|
||||||
|
- SPDX-FileCopyrightText: 2022 Serokell <https://serokell.io>
|
||||||
|
-
|
||||||
|
- SPDX-License-Identifier: MPL-2.0
|
||||||
|
-->
|
||||||
|
|
||||||
|
# File with no anchors
|
@ -1,2 +0,0 @@
|
|||||||
# SPDX-FileCopyrightText: 2022 Serokell <https://serokell.io>
|
|
||||||
# SPDX-License-Identifier: Unlicense
|
|
@ -1,2 +0,0 @@
|
|||||||
# SPDX-FileCopyrightText: 2021 Serokell <https://serokell.io>
|
|
||||||
# SPDX-License-Identifier: Unlicense
|
|
Loading…
Reference in New Issue
Block a user