@@ -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.
253257fn 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