Skip to content

Commit

Permalink
fix(flaws): ignore casing of text fragments (#9882)
Browse files Browse the repository at this point in the history
* refactor(flaws): extract checkHash()

* fix(flaws): ignore fragment directives in hashs
  • Loading branch information
caugner authored Oct 26, 2023
1 parent 58b33b9 commit fc51e08
Showing 1 changed file with 23 additions and 20 deletions.
43 changes: 23 additions & 20 deletions build/flaws/broken-links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,26 @@ export function getBrokenLinksFlaws(
});
}

function checkHash(
hash: string,
a: cheerio.Cheerio<cheerio.Element>,
href: string
) {
if (hash.startsWith(":~:")) {
// Ignore fragment directives.
return;
}
if (hash !== hash.toLowerCase()) {
addBrokenLink(
a,
checked.get(href),
href,
href.replace(`#${hash}`, `#${hash.toLowerCase()}`),
"Anchor not lowercase"
);
}
}

$("a[href]").each((i, element) => {
const a = $(element);
let href = a.attr("href");
Expand Down Expand Up @@ -347,30 +367,13 @@ export function getBrokenLinksFlaws(
href,
found.url + absoluteURL.search + absoluteURL.hash.toLowerCase()
);
} else if (
hrefSplit.length > 1 &&
hrefSplit[1] !== hrefSplit[1].toLowerCase()
) {
} else if (hrefSplit.length > 1) {
const hash = hrefSplit[1];
addBrokenLink(
a,
checked.get(href),
href,
href.replace(`#${hash}`, `#${hash.toLowerCase()}`),
"Anchor not lowercase"
);
checkHash(hash, a, href);
}
} else if (href.startsWith("#")) {
const hash = href.split("#")[1];
if (hash !== hash.toLowerCase()) {
addBrokenLink(
a,
checked.get(href),
href,
href.replace(`#${hash}`, `#${hash.toLowerCase()}`),
"Anchor not lowercase"
);
}
checkHash(hash, a, href);
}
});

Expand Down

0 comments on commit fc51e08

Please sign in to comment.