Skip to content

Commit fdbad08

Browse files
committed
fix(command): Improve URI validation
1 parent 7941761 commit fdbad08

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/app/commands.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ pub enum CommandError {
3636
#[error("Could not infer ID from flake reference: {0}")]
3737
CouldNotInferId(String),
3838

39+
#[error("Invalid URI: {0}")]
40+
InvalidUri(String),
41+
3942
#[error("No inputs found in the flake")]
4043
NoInputs,
4144

@@ -248,17 +251,18 @@ fn apply_uri_options(
248251

249252
/// Transform a URI string by applying ref_or_rev and shallow options if specified.
250253
///
251-
/// If neither option is set, returns the original URI unchanged.
252-
/// Otherwise, parses the URI, applies the options, and returns the transformed string.
254+
/// Always validates the URI through nix-uri parsing.
255+
/// If neither option is set, returns the original URI unchanged after validation.
256+
/// Otherwise, applies the options and returns the transformed string.
253257
fn transform_uri(uri: String, ref_or_rev: Option<&str>, shallow: bool) -> Result<String> {
258+
let flake_ref: FlakeRef = uri
259+
.parse()
260+
.map_err(|e| CommandError::InvalidUri(format!("{}: {}", uri, e)))?;
261+
254262
if ref_or_rev.is_none() && !shallow {
255263
return Ok(uri);
256264
}
257265

258-
let flake_ref: FlakeRef = uri
259-
.parse()
260-
.map_err(|e| CommandError::CouldNotInferId(format!("{}: {}", uri, e)))?;
261-
262266
apply_uri_options(flake_ref, ref_or_rev, shallow)
263267
.map(|f| f.to_string())
264268
.map_err(CommandError::CouldNotInferId)

0 commit comments

Comments
 (0)