mirror of https://github.com/astral-sh/uv
Ignore 'egg' fragment in HTML Simple API response (#11340)
## Summary Closes https://github.com/astral-sh/uv/issues/11339.
This commit is contained in:
parent
e22ecee36b
commit
5d8168875a
|
|
@ -109,9 +109,15 @@ impl SimpleHtml {
|
||||||
debug!("{err}");
|
debug!("{err}");
|
||||||
Hashes::default()
|
Hashes::default()
|
||||||
}
|
}
|
||||||
Err(err @ HashError::UnsupportedHashAlgorithm(..)) => {
|
Err(HashError::UnsupportedHashAlgorithm(fragment)) => {
|
||||||
// If the URL references a hash, but it's unsupported, error.
|
if fragment == "egg" {
|
||||||
return Err(err.into());
|
// If the URL references an egg hash, ignore it.
|
||||||
|
debug!("{}", HashError::UnsupportedHashAlgorithm(fragment));
|
||||||
|
Hashes::default()
|
||||||
|
} else {
|
||||||
|
// If the URL references a hash, but it's unsupported, error.
|
||||||
|
return Err(HashError::UnsupportedHashAlgorithm(fragment).into());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
@ -247,7 +253,7 @@ pub enum Error {
|
||||||
MissingHash(String),
|
MissingHash(String),
|
||||||
|
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
FragmentParse(#[from] uv_pypi_types::HashError),
|
FragmentParse(#[from] HashError),
|
||||||
|
|
||||||
#[error("Invalid `requires-python` specifier: {0}")]
|
#[error("Invalid `requires-python` specifier: {0}")]
|
||||||
Pep440(#[source] uv_pep440::VersionSpecifiersParseError),
|
Pep440(#[source] uv_pep440::VersionSpecifiersParseError),
|
||||||
|
|
@ -908,6 +914,64 @@ mod tests {
|
||||||
"###);
|
"###);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parse_egg_fragment() {
|
||||||
|
let text = r#"
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
<h1>Links for jinja2</h1>
|
||||||
|
<a href="/whl/Jinja2-3.1.2-py3-none-any.whl#main">Jinja2-3.1.2-py3-none-any.whl#egg=public-hello-0.1</a><br/>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
<!--TIMESTAMP 1703347410-->
|
||||||
|
"#;
|
||||||
|
let base = Url::parse("https://download.pytorch.org/whl/jinja2/").unwrap();
|
||||||
|
let result = SimpleHtml::parse(text, &base);
|
||||||
|
insta::assert_debug_snapshot!(result, @r###"
|
||||||
|
Ok(
|
||||||
|
SimpleHtml {
|
||||||
|
base: BaseUrl(
|
||||||
|
Url {
|
||||||
|
scheme: "https",
|
||||||
|
cannot_be_a_base: false,
|
||||||
|
username: "",
|
||||||
|
password: None,
|
||||||
|
host: Some(
|
||||||
|
Domain(
|
||||||
|
"download.pytorch.org",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
port: None,
|
||||||
|
path: "/whl/jinja2/",
|
||||||
|
query: None,
|
||||||
|
fragment: None,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
files: [
|
||||||
|
File {
|
||||||
|
core_metadata: None,
|
||||||
|
dist_info_metadata: None,
|
||||||
|
data_dist_info_metadata: None,
|
||||||
|
filename: "Jinja2-3.1.2-py3-none-any.whl",
|
||||||
|
hashes: Hashes {
|
||||||
|
md5: None,
|
||||||
|
sha256: None,
|
||||||
|
sha384: None,
|
||||||
|
sha512: None,
|
||||||
|
},
|
||||||
|
requires_python: None,
|
||||||
|
size: None,
|
||||||
|
upload_time: None,
|
||||||
|
url: "/whl/Jinja2-3.1.2-py3-none-any.whl#main",
|
||||||
|
yanked: None,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
)
|
||||||
|
"###);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_unknown_hash() {
|
fn parse_unknown_hash() {
|
||||||
let text = r#"
|
let text = r#"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue