[#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:
Sergey Gulin 2022-08-31 03:05:18 +10:00
parent fd147e6856
commit 36a1da6473
No known key found for this signature in database
GPG Key ID: 67CBDE9BE7E6399B
9 changed files with 54 additions and 5 deletions

View File

@ -11,3 +11,7 @@ License: Unlicense
Files: tests/configs/github-config.yaml
Copyright: 2019-2021 Serokell <https://serokell.io>
License: Unlicense
Files: tests/golden/**/*.gold
Copyright: 2022 Serokell <https://serokell.io>
License: Unlicense

View File

@ -33,6 +33,8 @@ Unreleased
+ Add support for the `id` attribute in anchors.
* [#116](https://github.com/serokell/xrefcheck/pull/116)
+ 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
==========

View File

@ -308,7 +308,7 @@ verifyReference
then case locType of
LocalLoc -> checkRef rAnchor fileWithReference
RelativeLoc -> checkRef rAnchor
(takeDirectory fileWithReference
(normalise $ takeDirectory fileWithReference
</> toString (canonizeLocalRef rLink))
AbsoluteLoc -> checkRef rAnchor (root <> toString rLink)
ExternalLoc -> checkExternalResource config rLink

View 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
}

View 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)

View 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.

View File

@ -0,0 +1,7 @@
<!--
- SPDX-FileCopyrightText: 2022 Serokell <https://serokell.io>
-
- SPDX-License-Identifier: MPL-2.0
-->
# File with no anchors

View File

@ -1,2 +0,0 @@
# SPDX-FileCopyrightText: 2022 Serokell <https://serokell.io>
# SPDX-License-Identifier: Unlicense

View File

@ -1,2 +0,0 @@
# SPDX-FileCopyrightText: 2021 Serokell <https://serokell.io>
# SPDX-License-Identifier: Unlicense