-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#138] Report links that escape repo directory
Problem: as in #138, when we see a local link, we are checking only existance of referred file, not checking that this file is a part of repo and link will compatible with Github's renderer Solution: manually count "nesting levels" of all local links, checking that number of `".."`'s is always less then number of real directories
- Loading branch information
1 parent
0fd2b8a
commit 11eacca
Showing
5 changed files
with
87 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
tests/golden/check-local-references-outside-repo/check-local-references-outside-repo.bats
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/usr/bin/env bats | ||
|
||
# SPDX-FileCopyrightText: 2021 Serokell <https://serokell.io> | ||
# | ||
# SPDX-License-Identifier: MPL-2.0 | ||
|
||
load '../helpers/bats-support/load' | ||
load '../helpers/bats-assert/load' | ||
load '../helpers' | ||
|
||
@test "We report all links that target files outside root" { | ||
xrefcheck -r inner-directory\ | ||
| prepare > /tmp/check-notScanned.test || true | ||
|
||
diff /tmp/check-notScanned.test expected.gold \ | ||
--ignore-space-change \ | ||
--ignore-blank-lines \ | ||
--new-file # treat absent files as empty | ||
|
||
rm /tmp/check-notScanned.test | ||
} | ||
|
||
@test "When target is inside repo root, everything is good" { | ||
run xrefcheck -r .\ | ||
|
||
assert_output --partial "All repository links are valid." | ||
} |
23 changes: 23 additions & 0 deletions
23
tests/golden/check-local-references-outside-repo/expected.gold
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
=== Invalid references found === | ||
|
||
➥ In file inner-directory/check-local-references-outside-repo.md | ||
bad reference (relative) at src:7:1-35: | ||
- text: "Without anchor" | ||
- link: ../link-target.md | ||
- anchor: - | ||
|
||
⛀ Link targets a local file outside repository: | ||
inner-directory/../link-target.md | ||
|
||
|
||
➥ In file inner-directory/check-local-references-outside-repo.md | ||
bad reference (relative) at src:8:1-51: | ||
- text: "With anchor" | ||
- link: ../link-target.md | ||
- anchor: link-target-anchor | ||
|
||
⛀ Link targets a local file outside repository: | ||
inner-directory/../link-target.md | ||
|
||
|
||
Invalid references dumped, 2 in total. |
8 changes: 8 additions & 0 deletions
8
...-references-outside-repo/inner-directory/check-local-references-outside-repo.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<!-- | ||
- SPDX-FileCopyrightText: 2021 Serokell <https://serokell.io> | ||
- | ||
- SPDX-License-Identifier: MPL-2.0 | ||
--> | ||
|
||
[Without anchor](../link-target.md) | ||
[With anchor](../link-target.md#link-target-anchor) |
7 changes: 7 additions & 0 deletions
7
tests/golden/check-local-references-outside-repo/link-target.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<!-- | ||
- SPDX-FileCopyrightText: 2022 Serokell <https://serokell.io> | ||
- | ||
- SPDX-License-Identifier: MPL-2.0 | ||
--> | ||
|
||
# Link target anchor |