Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions crates/uv-requirements-txt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,29 +275,27 @@ impl RequirementsTxt {

#[cfg(feature = "http")]
{
let url = requirements_txt.display().to_string();
let url = DisplaySafeUrl::parse(&url).map_err(|err| RequirementsTxtFileError {
file: requirements_txt.to_path_buf(),
error: RequirementsTxtParserError::InvalidUrl(
requirements_txt.display().to_string(),
err,
),
})?;

// Avoid constructing a client if network is disabled already
if client_builder.is_offline() {
return Err(RequirementsTxtFileError {
file: requirements_txt.to_path_buf(),
error: RequirementsTxtParserError::Io(io::Error::new(
io::ErrorKind::InvalidInput,
format!(
"Network connectivity is disabled, but a remote requirements file was requested: {}",
requirements_txt.display()
"Network connectivity is disabled, but a remote requirements file was requested: {url}"
),
)),
});
}

let url = DisplaySafeUrl::parse(&requirements_txt.display().to_string()).map_err(
|err| RequirementsTxtFileError {
file: requirements_txt.to_path_buf(),
error: RequirementsTxtParserError::InvalidUrl(
requirements_txt.display().to_string(),
err,
),
},
)?;
let client = client_builder
.build()
.map_err(|err| RequirementsTxtFileError {
Expand Down
23 changes: 23 additions & 0 deletions crates/uv/tests/it/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4799,6 +4799,29 @@ fn run_remote_pep723_script() {
");
}

#[test]
fn run_remote_requirements_offline_redacts_credentials() -> Result<()> {
let context = uv_test::test_context!("3.12");

let script = context.temp_dir.child("main.py");
script.write_str("print('hello')")?;

uv_snapshot!(context.filters(), context.run()
.arg("--offline")
.arg("--with-requirements")
.arg("http://username:password@example.com/requirements.txt")
.arg(script.as_os_str()), @"
success: false
exit_code: 2
----- stdout -----

----- stderr -----
error: Network connectivity is disabled, but a remote requirements file was requested: http://username:****@example.com/requirements.txt
");

Ok(())
}

#[cfg(unix)] // A URL could be a valid filepath on Unix but not on Windows
#[test]
fn run_url_like_with_local_file_priority() -> Result<()> {
Expand Down
Loading