Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

16 changes: 10 additions & 6 deletions src/check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,16 @@ async function checkInternal(link: LinkInfo, config: Config): Promise<CheckResul
return { link, ok: true };
}

const isRootRelative = urlWithoutAnchor.startsWith('/');
// Decode percent-encoded characters (e.g. %20 for spaces) so the path
// matches the actual filename on disk.
const decodedPath = decodeURIComponent(urlWithoutAnchor);

const isRootRelative = decodedPath.startsWith('/');
const sourceDir = path.dirname(path.join(config.repoRoot, link.filePath));

const resolvedPath = isRootRelative
? path.join(config.repoRoot, urlWithoutAnchor)
: path.resolve(sourceDir, urlWithoutAnchor);
? path.join(config.repoRoot, decodedPath)
: path.resolve(sourceDir, decodedPath);

const exists = fs.existsSync(resolvedPath);

Expand All @@ -251,9 +255,9 @@ async function checkInternal(link: LinkInfo, config: Config): Promise<CheckResul

// --- Link is broken: search for the target file ---

const filename = path.basename(urlWithoutAnchor);
const stem = path.basename(urlWithoutAnchor, path.extname(urlWithoutAnchor));
const ext = path.extname(urlWithoutAnchor);
const filename = path.basename(decodedPath);
const stem = path.basename(decodedPath, path.extname(decodedPath));
const ext = path.extname(decodedPath);

let correctedAbs: string | undefined;
let isFuzzy = false;
Expand Down
9 changes: 5 additions & 4 deletions tests/expected-output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ tests/test-document.md:35 | ./configuration.md | broken -> /docs/configuration.m
tests/test-document.md:37 | ./placeholder.md | ok
tests/test-document.md:41 | ../AGENTS.md | suggestion
tests/test-document.md:43 | ../action.yml | suggestion
tests/test-document.md:53 | https://github.com/dvdstelt/hyperhawk/blob/main/README.md | suggestion -> /README.md
tests/test-document.md:55 | https://github.com/dvdstelt/hyperhawk/blob/main/tests/test-document.md | suggestion -> test-document.md
tests/test-document.md:57 | https://github.com/dvdstelt/hyperhawk/blob/main/does-not-exist.md | broken -> /does-not-exist.md
tests/test-document.md:59 | https://github.com/dvdstelt/hyperhawk/blob/main/docs/configuraton.md | broken -> /docs/configuration.md (fuzzy)
tests/test-document.md:47 | ./file%20with%20spaces.md | ok
tests/test-document.md:57 | https://github.com/dvdstelt/hyperhawk/blob/main/README.md | suggestion -> /README.md
tests/test-document.md:59 | https://github.com/dvdstelt/hyperhawk/blob/main/tests/test-document.md | suggestion -> test-document.md
tests/test-document.md:61 | https://github.com/dvdstelt/hyperhawk/blob/main/does-not-exist.md | broken -> /does-not-exist.md
tests/test-document.md:63 | https://github.com/dvdstelt/hyperhawk/blob/main/docs/configuraton.md | broken -> /docs/configuration.md (fuzzy)
tests/test-document.md:7 | ../READM.md | broken -> /README.md (fuzzy)
tests/test-document.md:9 | ../LICENS.md | broken | File not found: <root>/LICENS.md
merge:tests/test-document.md:31 | ../READM.md + ../LICENS.md | Read the [README](/README.md) and the [license](../LICENS.md) before starting.
3 changes: 3 additions & 0 deletions tests/file with spaces.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# File With Spaces

This file has spaces in its name to test percent-encoded link resolution.
4 changes: 4 additions & 0 deletions tests/test-document.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ Look at the [agents guide](../AGENTS.md) for coding conventions.

The [action config](../action.yml) has all the inputs documented.

## Percent-encoded Paths (spaces in filenames)

See the [file with spaces](./file%20with%20spaces.md) for an example.

## Skipped Links (should not be checked)

Contact us at [email](mailto:user@domain.net) for support.
Expand Down