Skip to content

Commit

Permalink
fixup! fixup! fixup! [#138] Report links that escape repo directory
Browse files Browse the repository at this point in the history
  • Loading branch information
Sorokin-Anton committed Oct 3, 2022
1 parent 09186a6 commit 1d5d68a
Show file tree
Hide file tree
Showing 11 changed files with 185 additions and 111 deletions.
2 changes: 1 addition & 1 deletion src/Xrefcheck/Verify.hs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ import Network.HTTP.Types.Header (hRetryAfter)
import Network.HTTP.Types.Status (Status, statusCode, statusMessage)
import System.Console.Pretty (Style (..), style)
import System.Directory (doesDirectoryExist, doesFileExist)
import System.FilePath (takeDirectory, (</>), normalise, splitDirectories, makeRelative)
import System.FilePath (makeRelative, normalise, splitDirectories, takeDirectory, (</>))
import Text.ParserCombinators.ReadPrec qualified as ReadPrec (lift)
import Text.Regex.TDFA.Text (Regex, regexec)
import Text.URI (Authority (..), ParseExceptionBs, URI (..), mkURIBs)
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

6 changes: 6 additions & 0 deletions tests/golden/check-local-refs/check-local-refs.bats
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,9 @@ load '../helpers'

assert_diff expected2.gold
}

@test "Checking behavior when there are virtual files, root = \"dir1\"" {
to_temp xrefcheck -r dir1 -c config-with-virtual-files.yaml

assert_diff expected3.gold
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
# SPDX-License-Identifier: Unlicense
verification:
virtualFiles:
- ../link-target.md
- ../d0f1.md
- ../../a.md
- b/../../*
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
- SPDX-License-Identifier: MPL-2.0
-->

# Link target anchor
We are testing links in [this](dir1/dir2/d2f1.md) file

12 changes: 12 additions & 0 deletions tests/golden/check-local-refs/dir1/dir2/d2f1.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,15 @@ Should be correct when root is `/tests/golden/check-local-refs/dir1`:
[file-abs-3](/dir2/d2f2.md)
[file-abs-4](/./dir2/../d1f1.md)
[anchor-abs-3](/./dir2/../d1f1.md#existing-anchor-d1f1)

# Test references outside repo

This should be reported as "reference to file outside repo" when root is `dir1`
[path-through-top-dir](../../dir1/d1f1.md)
[path-through-top-dir-with-anchor](../../dir1/d1f1.md#existing-anchor-d1f1)
[ref-to-d0](../../d0f1.md)

Such absoulute paths should be reported,
unless we specify in config that we ignore references to them
[A](/../../a.md)
[B](/b/../../b.md)
22 changes: 21 additions & 1 deletion tests/golden/check-local-refs/expected1.gold
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,24 @@
././dir2/../d1f1.md


Invalid references dumped, 9 in total.
➥ In file dir1/dir2/d2f1.md
bad reference (absolute) at src:46:1-16:
- text: "A"
- link: /../../a.md
- anchor: -

⛀ Link targets a local file outside repository:
./../../a.md


➥ In file dir1/dir2/d2f1.md
bad reference (absolute) at src:47:1-18:
- text: "B"
- link: /b/../../b.md
- anchor: -

⛀ Link targets a local file outside repository:
./b/../../b.md


Invalid references dumped, 11 in total.
52 changes: 51 additions & 1 deletion tests/golden/check-local-refs/expected2.gold
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,54 @@
dir1/dir1/dir2/../../dir1/./dir2/d2f2.md


Invalid references dumped, 7 in total.
➥ In file dir1/dir2/d2f1.md
bad reference (relative) at src:40:1-42:
- text: "path-through-top-dir"
- link: ../../dir1/d1f1.md
- anchor: -

⛀ Link targets a local file outside repository:
dir1/dir2/../../dir1/d1f1.md


➥ In file dir1/dir2/d2f1.md
bad reference (relative) at src:41:1-75:
- text: "path-through-top-dir-with-anchor"
- link: ../../dir1/d1f1.md
- anchor: existing-anchor-d1f1

⛀ Link targets a local file outside repository:
dir1/dir2/../../dir1/d1f1.md


➥ In file dir1/dir2/d2f1.md
bad reference (relative) at src:42:1-26:
- text: "ref-to-d0"
- link: ../../d0f1.md
- anchor: -

⛀ Link targets a local file outside repository:
dir1/dir2/../../d0f1.md


➥ In file dir1/dir2/d2f1.md
bad reference (absolute) at src:46:1-16:
- text: "A"
- link: /../../a.md
- anchor: -

⛀ Link targets a local file outside repository:
dir1/../../a.md


➥ In file dir1/dir2/d2f1.md
bad reference (absolute) at src:47:1-18:
- text: "B"
- link: /b/../../b.md
- anchor: -

⛀ Link targets a local file outside repository:
dir1/b/../../b.md


Invalid references dumped, 12 in total.
91 changes: 91 additions & 0 deletions tests/golden/check-local-refs/expected3.gold
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
=== Invalid references found ===

➥ In file dir1/dir2/d2f1.md
bad reference (current file) at src:9:1-18:
- text: "bad-cf-ref"
- link:
- anchor: bad

⛀ Anchor 'bad' is not present


➥ In file dir1/dir2/d2f1.md
bad reference (relative) at src:21:1-43:
- text: "bad-file-rel"
- link: ../a/b/c/unexisting-file.md
- anchor: -

⛀ File does not exist:
dir1/dir2/../a/b/c/unexisting-file.md


➥ In file dir1/dir2/d2f1.md
bad reference (relative) at src:23:1-38:
- text: "bad-anchor-rel-1"
- link: d2f2.md
- anchor: bad-anchor

⛀ Anchor 'bad-anchor' is not present


➥ In file dir1/dir2/d2f1.md
bad reference (relative) at src:24:1-49:
- text: "bad-anchor-rel-2"
- link: unexisting-file.md
- anchor: bad-anchor

⛀ File does not exist:
dir1/dir2/unexisting-file.md


➥ In file dir1/dir2/d2f1.md
bad reference (absolute) at src:28:1-29:
- text: "file-abs-1"
- link: /dir1/./d1f1.md
- anchor: -

⛀ File does not exist:
dir1/dir1/./d1f1.md


➥ In file dir1/dir2/d2f1.md
bad reference (absolute) at src:29:1-55:
- text: "anchor-abs-1"
- link: /dir1/.././d1f1.md
- anchor: existing-anchor-d1f1

⛀ File does not exist:
dir1/dir1/.././d1f1.md


➥ In file dir1/dir2/d2f1.md
bad reference (absolute) at src:30:1-73:
- text: "anchor-abs-2"
- link: /dir1/dir2/../../dir1/./dir2/d2f2.md
- anchor: existing-anchor-d2f2

⛀ File does not exist:
dir1/dir1/dir2/../../dir1/./dir2/d2f2.md


➥ In file dir1/dir2/d2f1.md
bad reference (relative) at src:40:1-42:
- text: "path-through-top-dir"
- link: ../../dir1/d1f1.md
- anchor: -

⛀ Link targets a local file outside repository:
dir1/dir2/../../dir1/d1f1.md


➥ In file dir1/dir2/d2f1.md
bad reference (relative) at src:41:1-75:
- text: "path-through-top-dir-with-anchor"
- link: ../../dir1/d1f1.md
- anchor: existing-anchor-d1f1

⛀ Link targets a local file outside repository:
dir1/dir2/../../dir1/d1f1.md


Invalid references dumped, 9 in total.

0 comments on commit 1d5d68a

Please sign in to comment.