mirror of
https://github.com/Hopiu/lychee.git
synced 2026-03-16 20:50:25 +00:00
fix: do not check the fragment when http response err but accepted (#1763)
Signed-off-by: Keming <kemingy94@gmail.com>
This commit is contained in:
parent
068b4850d5
commit
696a7cafc8
4 changed files with 30 additions and 2 deletions
5
fixtures/TEST_FRAGMENT_ERR_CODE.md
vendored
Normal file
5
fixtures/TEST_FRAGMENT_ERR_CODE.md
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
Requesting a 404 page from Wikipedia.
|
||||
|
||||
It's common for user to accept 429, but let's test with 404 since triggering 429 may annoy the server.
|
||||
|
||||
- [404 Wikipedia Page](https://en.wikipedia.org/wiki/Should404#ignore-fragment)
|
||||
|
|
@ -1920,6 +1920,27 @@ mod cli {
|
|||
.stdout(contains("12 Errors"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_fragments_when_accept_error_status_codes() {
|
||||
let mut cmd = main_command();
|
||||
let input = fixtures_path().join("TEST_FRAGMENT_ERR_CODE.md");
|
||||
|
||||
// it's common for user to accept 429, but let's test with 404 since
|
||||
// triggering 429 may annoy the server
|
||||
cmd.arg("--verbose")
|
||||
.arg("--accept=200,404")
|
||||
.arg("--include-fragments")
|
||||
.arg(input)
|
||||
.assert()
|
||||
.success()
|
||||
.stderr(contains(
|
||||
"https://en.wikipedia.org/wiki/Should404#ignore-fragment",
|
||||
))
|
||||
.stdout(contains("0 Errors"))
|
||||
.stdout(contains("1 OK"))
|
||||
.stdout(contains("1 Total"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_fallback_extensions() {
|
||||
let mut cmd = main_command();
|
||||
|
|
|
|||
|
|
@ -103,8 +103,10 @@ impl WebsiteChecker {
|
|||
match self.reqwest_client.execute(request).await {
|
||||
Ok(response) => {
|
||||
let status = Status::new(&response, &self.accepted);
|
||||
// when `accept=200,429`, `status_code=429` will be treated as success
|
||||
// but we are not able the check the fragment since it's inapplicable.
|
||||
if self.include_fragments
|
||||
&& status.is_success()
|
||||
&& response.status().is_success()
|
||||
&& method == Method::GET
|
||||
&& response.url().fragment().is_some_and(|x| !x.is_empty())
|
||||
{
|
||||
|
|
|
|||
|
|
@ -139,7 +139,7 @@ pub(crate) fn extract_markdown(input: &str, include_verbatim: bool) -> Vec<RawUr
|
|||
.collect()
|
||||
}
|
||||
|
||||
/// Extract fragments/anchors/fragments from a Markdown string.
|
||||
/// Extract fragments/anchors from a Markdown string.
|
||||
///
|
||||
/// Fragments are generated from headings using the same unique kebab case method as GitHub.
|
||||
/// If a [heading attribute](https://github.com/raphlinus/pulldown-cmark/blob/master/specs/heading_attrs.txt)
|
||||
|
|
|
|||
Loading…
Reference in a new issue