Skip to content

Commit a7c8a2c

Browse files
committed
ignore nonroot redirects
1 parent 4931ae5 commit a7c8a2c

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

src/html/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ impl Document {
318318
'b: 'l,
319319
F: FnMut(Link<'l, P::Paragraph>),
320320
{
321-
if self.path.file_name().and_then(|f| f.to_str()) == Some("_redirects") {
321+
if self.href == "_redirects" {
322322
for link in self.parse_redirects::<P>(doc_buf, check_anchors)? {
323323
callback(link);
324324
}

tests/cli.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,40 @@ Found 1 bad links
106106

107107
site.close().unwrap();
108108
}
109+
110+
#[test]
111+
fn test_redirects_only_at_root() {
112+
let site = assert_fs::TempDir::new().unwrap();
113+
114+
site.child("_redirects")
115+
.write_str("/old-page /new-page.html")
116+
.unwrap();
117+
118+
site.child("subdir/_redirects")
119+
.write_str("/sub-old /sub-new.html")
120+
.unwrap();
121+
122+
site.child("new-page.html").touch().unwrap();
123+
124+
site.child("index.html")
125+
.write_str("<a href='/old-page'>link to old</a><a href='/sub-old'>link to sub</a>")
126+
.unwrap();
127+
128+
let mut cmd = Command::cargo_bin("hyperlink").unwrap();
129+
cmd.current_dir(site.path()).arg(".");
130+
131+
cmd.assert().failure().code(1).stdout(
132+
predicate::str::is_match(
133+
r#"^Reading files
134+
Checking 3 links from 4 files \(3 documents\)
135+
\./index\.html
136+
error: bad link /sub-old
137+
138+
Found 1 bad links
139+
"#,
140+
)
141+
.unwrap(),
142+
);
143+
144+
site.close().unwrap();
145+
}

0 commit comments

Comments
 (0)