wjdp / htmltest

:white_check_mark: Test generated HTML for problems
MIT License
323 stars 54 forks source link

Internal links to files in symbolic link directories throw "target does not exist" error #198

Open nickvigilante opened 1 year ago

nickvigilante commented 1 year ago

Describe the bug

Within the CockroachDB docs, we have the concept of a stable version and a dev version. We create a symbolic link for each of those versions in our docs site, so navigating to cockroachlabs.com/docs/stable/add-column.html points to the exact same page as cockroachlabs.com/docs/v22.1/add-column.html. Below is an abridged view of our directory structure:

$ tree -d -L 1 .
├── advisories
│   ├── a88407.html
├── dev -> v22.2
├── stable -> v22.1
├── v22.1
│   ├── multiregion-overview.html
├── v22.2
│   ├── page2.html
└── vale

We have a link defined in a88407.html with a target of ../stable/multiregion-overview.html#regional-by-row-tables. We're noticing that htmltest will throw an error:

docs/advisories/a88407.html
  hash does not exist --- docs/advisories/a88407.html --> ../stable/multiregion-overview.html#regional-by-row-tables

If we change it to ../v22.1/multiregion-overview.html#regional-by-row-tables, it works fine. However, we want to point forever to stable, as the stable URL will rotate based on the latest GA release of our software.

To Reproduce

Steps to reproduce the behaviour:

  1. Create a new folder somewhere.
  2. In this folder, run the following:
mkdir s_dir
mkdir t_dir
ln -s t_ln t_dir

touch s_dir/s_file_ln.html
echo '<a href="../t_ln/t_file.html"><code>Click me</code></a>' >> s_dir/s_file_ln.html
# the above file uses the symbolic link directory

touch s_dir/s_file_dir.html
echo '<a href="../t_dir/t_file.html"><code>Click me</code></a>' > s_dir/s_file_dir.html
# the above file uses the real directory

touch t_dir/t_file.html
echo '<h1>Hello</h1>' > t_dir/t_file.html

touch .htmltest.yml
echo 'DirectoryPath: "."' >> .htmltest.yml
echo 'CheckDoctype: false' >> .htmltest.yml

htmltest
  1. Observe how only s_file_ln.html, the file with the symbolic link, throws an error:
========================================================================
s_dir/s_file_ln.html
  target does not exist --- s_dir/s_file_ln.html --> ../t_ln/t_file.html
========================================================================
✘✘✘ failed in 1.270165ms
1 errors in 3 documents

.htmltest.yml

Please copy in your config file

DirectoryPath: "."
CheckDoctype: false

Our full .htmltest.yml can be found here: https://github.com/cockroachdb/docs/blob/master/.htmltest.yml

If you wish to reproduce on our main site, do the following:

  1. Follow the steps in the Setup section of our Contributing guide.
  2. In your local fork, remove line 11:
  - ^docs/advisories
  1. Run htmltest -s.

Source files

See To Reproduce.

Expected behaviour

No error should be returned on files referenced via symbolic link.

Actual behaviour

The following error is thrown when referencing a file through a symbolically linked directory:

========================================================================
s_dir/s_file_ln.html
  target does not exist --- s_dir/s_file_ln.html --> ../t_ln/t_file.html
========================================================================
✘✘✘ failed in 1.270165ms
1 errors in 3 documents

Versions