From c7633755a9fbb65d555c60b39a774d97e9d60ffe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1n=20Enr=C3=ADquez?= Date: Thu, 12 Jan 2023 20:11:55 +0100 Subject: [PATCH 1/2] [Chore] Fix changelog typo Problem: There is a duplicated line in the changelog unreleased section, which seems to be an accidental copy-paste typo or a bad merge conflict resolution. Solution: Delete the aforementioned changelog line. --- CHANGES.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 2cc88d2c..5fef4840 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -44,7 +44,6 @@ Unreleased * [#254](https://github.com/serokell/xrefcheck/pull/254) + Now the `dump-config` command does not overwrite a file unless explicitly told with a `--force` flag. Also, a `--stdout` flag allows to print the config to stdout instead. - the configured Markdown flavour. * [#250](https://github.com/serokell/xrefcheck/pull/250) + Now the redirect behavior for external references can be modified via rules in the configuration file with the `externalRefRedirects` parameter. From fef5153d3a4f3ea0310b7fc910b3df9e7f6a79f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1n=20Enr=C3=ADquez?= Date: Thu, 12 Jan 2023 20:12:43 +0100 Subject: [PATCH 2/2] [#242] No scan symlinks as md files Problem: When the repository contains a symlink to a markdown file, it is processed by xrefcheck as if it was the same markdown file but in the symlink's location. This leads to broken references and can be avoided because neither GitHub nor GitLab try to render symlinks as the file they point to. Solution: Consider symlinks as no scannable files. In the future, we will consider to include a new dedicated scanner for symlinks if it works. --- CHANGES.md | 2 ++ src/Xrefcheck/Scan.hs | 5 ++++- src/Xrefcheck/System.hs | 5 +++++ .../golden/check-symlinks/check-symlinks.bats | 17 ++++++++++++++++ tests/golden/check-symlinks/dir/a | 0 tests/golden/check-symlinks/dir/b.md | 11 ++++++++++ tests/golden/check-symlinks/expected.gold | 20 +++++++++++++++++++ tests/golden/check-symlinks/s.md | 1 + 8 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 tests/golden/check-symlinks/check-symlinks.bats create mode 100644 tests/golden/check-symlinks/dir/a create mode 100644 tests/golden/check-symlinks/dir/b.md create mode 100644 tests/golden/check-symlinks/expected.gold create mode 120000 tests/golden/check-symlinks/s.md diff --git a/CHANGES.md b/CHANGES.md index 5fef4840..c96b3e91 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -47,6 +47,8 @@ Unreleased * [#250](https://github.com/serokell/xrefcheck/pull/250) + Now the redirect behavior for external references can be modified via rules in the configuration file with the `externalRefRedirects` parameter. +* [#261](https://github.com/serokell/xrefcheck/pull/261) + + Symlinks are now not processed by the scanner. 0.2.2 ========== diff --git a/src/Xrefcheck/Scan.hs b/src/Xrefcheck/Scan.hs index f3928b78..2cdee8c1 100644 --- a/src/Xrefcheck/Scan.hs +++ b/src/Xrefcheck/Scan.hs @@ -264,7 +264,10 @@ scanRepo scanMode rw formatsSupport config root = do gatherFileStatuses = map (second fst) processFile :: CanonicalPath -> IO (FileStatus, [ScanError 'Parse]) - processFile canonicalFile = case mscanner canonicalFile of + processFile canonicalFile = + ifM (pathIsSymbolicLink canonicalFile) + (pure (NotScannable, [])) + case mscanner canonicalFile of Nothing -> pure (NotScannable, []) Just scanner -> scanner canonicalFile <&> _1 %~ Scanned diff --git a/src/Xrefcheck/System.hs b/src/Xrefcheck/System.hs index 89d496d8..999f46f4 100644 --- a/src/Xrefcheck/System.hs +++ b/src/Xrefcheck/System.hs @@ -14,6 +14,7 @@ module Xrefcheck.System , getPosixRelativeChild , getPosixRelativeOrAbsoluteChild , hasIndirectionThroughParent + , pathIsSymbolicLink , takeDirectory , takeExtension , ( String takeExtension (UnsafeCanonicalPath p) = FP.takeExtension p +-- | 'System.Directory.pathIsSymbolicLink' version for 'CanonicalPath'. +pathIsSymbolicLink :: CanonicalPath -> IO Bool +pathIsSymbolicLink (UnsafeCanonicalPath p) = Directory.pathIsSymbolicLink p + -- | Get the list of directories, canonicalized, between two given paths. getDirsBetweenRootAndFile :: CanonicalPath -> CanonicalPath -> [CanonicalPath] getDirsBetweenRootAndFile (UnsafeCanonicalPath rootPath) file = diff --git a/tests/golden/check-symlinks/check-symlinks.bats b/tests/golden/check-symlinks/check-symlinks.bats new file mode 100644 index 00000000..b2331c9a --- /dev/null +++ b/tests/golden/check-symlinks/check-symlinks.bats @@ -0,0 +1,17 @@ +#!/usr/bin/env bats + +# SPDX-FileCopyrightText: 2023 Serokell +# +# SPDX-License-Identifier: MPL-2.0 + +load '../helpers/bats-support/load' +load '../helpers/bats-assert/load' +load '../helpers/bats-file/load' +load '../helpers' + + +@test "Checking that symlinks are not processed" { + to_temp xrefcheck -v + + assert_diff expected.gold +} diff --git a/tests/golden/check-symlinks/dir/a b/tests/golden/check-symlinks/dir/a new file mode 100644 index 00000000..e69de29b diff --git a/tests/golden/check-symlinks/dir/b.md b/tests/golden/check-symlinks/dir/b.md new file mode 100644 index 00000000..12a137c8 --- /dev/null +++ b/tests/golden/check-symlinks/dir/b.md @@ -0,0 +1,11 @@ + + +[Empty file](a) + +[Symlink ref](../s.md) + +[Symlink ref with anchor](../s.md#a) diff --git a/tests/golden/check-symlinks/expected.gold b/tests/golden/check-symlinks/expected.gold new file mode 100644 index 00000000..f4b05c27 --- /dev/null +++ b/tests/golden/check-symlinks/expected.gold @@ -0,0 +1,20 @@ +=== Repository data === + + dir/b.md: + - references: + - reference (relative) at src:7:1-15: + - text: "Empty file" + - link: a + - anchor: - + - reference (relative) at src:9:1-22: + - text: "Symlink ref" + - link: ../s.md + - anchor: - + - reference (relative) at src:11:1-36: + - text: "Symlink ref with anchor" + - link: ../s.md + - anchor: a + - anchors: + none + +All repository links are valid. diff --git a/tests/golden/check-symlinks/s.md b/tests/golden/check-symlinks/s.md new file mode 120000 index 00000000..c92f149c --- /dev/null +++ b/tests/golden/check-symlinks/s.md @@ -0,0 +1 @@ +dir/b.md \ No newline at end of file