@@ -169,7 +169,7 @@ impl HostedGit {
169169 } ;
170170
171171 let parsed = parse_git_url ( normalised) ?;
172- // Look up host: shortcut first (so `github://… ` wins over the
172+ // Look up host: shortcut first (so `github://... ` wins over the
173173 // host's full URL parsing), then by domain.
174174 let shortcut_type = HostedGitType :: from_shortcut ( & parsed. scheme ) ;
175175 let domain_type = parsed. host . as_deref ( ) . and_then ( HostedGitType :: from_domain) ;
@@ -211,8 +211,8 @@ impl HostedGit {
211211 let committish = parsed
212212 . hash
213213 . as_ref ( )
214- . map ( |h | percent_decode ( h . strip_prefix ( '#' ) . unwrap_or ( h ) ) )
215- . filter ( |c | !c . is_empty ( ) ) ;
214+ . map ( |hash | percent_decode ( hash . strip_prefix ( '#' ) . unwrap_or ( hash ) ) )
215+ . filter ( |committish | !committish . is_empty ( ) ) ;
216216 let user = user. unwrap_or_default ( ) ;
217217 ( user, project, committish, Representation :: Shortcut )
218218 } else {
@@ -222,8 +222,10 @@ impl HostedGit {
222222 let segments = extract_for_host ( host_type, & parsed) ?;
223223 let user = percent_decode ( & segments. user ) ;
224224 let project = percent_decode ( & segments. project ) ;
225- let committish =
226- segments. committish . map ( |c| percent_decode ( & c) ) . filter ( |c| !c. is_empty ( ) ) ;
225+ let committish = segments
226+ . committish
227+ . map ( |raw| percent_decode ( & raw ) )
228+ . filter ( |decoded| !decoded. is_empty ( ) ) ;
227229 let representation = protocol_to_representation ( & parsed. scheme ) ;
228230 ( user, project, committish, representation)
229231 } ;
@@ -386,8 +388,8 @@ fn protocol_to_representation(protocol: &str) -> Representation {
386388 }
387389}
388390
389- fn strip_dot_git ( s : & str ) -> String {
390- s . strip_suffix ( ".git" ) . unwrap_or ( s ) . to_string ( )
391+ fn strip_dot_git ( project : & str ) -> String {
392+ project . strip_suffix ( ".git" ) . unwrap_or ( project ) . to_string ( )
391393}
392394
393395struct ParsedUrl {
@@ -505,9 +507,10 @@ fn is_github_shorthand(arg: &str) -> bool {
505507 }
506508 let first_hash = arg. find ( '#' ) ;
507509 let first_slash = arg. find ( '/' ) ;
508- let second_slash = first_slash. and_then ( |s| arg[ s + 1 ..] . find ( '/' ) . map ( |p| s + 1 + p) ) ;
510+ let second_slash =
511+ first_slash. and_then ( |first| arg[ first + 1 ..] . find ( '/' ) . map ( |rest| first + 1 + rest) ) ;
509512 let first_colon = arg. find ( ':' ) ;
510- let first_space = arg. find ( |c : char | c . is_whitespace ( ) ) ;
513+ let first_space = arg. find ( |ch : char | ch . is_whitespace ( ) ) ;
511514 let first_at = arg. find ( '@' ) ;
512515
513516 let space_only_after_hash = first_space. is_none ( )
@@ -518,9 +521,9 @@ fn is_github_shorthand(arg: &str) -> bool {
518521 || ( first_hash. is_some ( ) && first_colon. unwrap ( ) > first_hash. unwrap ( ) ) ;
519522 let second_slash_only_after_hash = second_slash. is_none ( )
520523 || ( first_hash. is_some ( ) && second_slash. unwrap ( ) > first_hash. unwrap ( ) ) ;
521- let has_slash = first_slash. is_some_and ( |s| s > 0 ) ;
524+ let has_slash = first_slash. is_some_and ( |first| first > 0 ) ;
522525 let does_not_end_with_slash = match first_hash {
523- Some ( h ) if h > 0 => arg. as_bytes ( ) [ h - 1 ] != b'/' ,
526+ Some ( hash ) if hash > 0 => arg. as_bytes ( ) [ hash - 1 ] != b'/' ,
524527 _ => !arg. ends_with ( '/' ) ,
525528 } ;
526529 let does_not_start_with_dot = !arg. starts_with ( '.' ) ;
@@ -564,7 +567,8 @@ fn extract_github(parsed: &ParsedUrl) -> Option<Segments> {
564567 }
565568
566569 if r#type. is_none ( ) {
567- committish = parsed. hash . as_deref ( ) . map ( |h| h. strip_prefix ( '#' ) . unwrap_or ( h) . to_string ( ) ) ;
570+ committish =
571+ parsed. hash . as_deref ( ) . map ( |hash| hash. strip_prefix ( '#' ) . unwrap_or ( hash) . to_string ( ) ) ;
568572 }
569573
570574 if project. ends_with ( ".git" ) {
@@ -598,8 +602,8 @@ fn extract_bitbucket(parsed: &ParsedUrl) -> Option<Segments> {
598602 let committish = parsed
599603 . hash
600604 . as_deref ( )
601- . map ( |h| h . strip_prefix ( '#' ) . unwrap_or ( h ) . to_string ( ) )
602- . filter ( |s | !s . is_empty ( ) ) ;
605+ . map ( |hash| hash . strip_prefix ( '#' ) . unwrap_or ( hash ) . to_string ( ) )
606+ . filter ( |committish | !committish . is_empty ( ) ) ;
603607 Some ( Segments { user, project, committish } )
604608}
605609
@@ -621,8 +625,8 @@ fn extract_gitlab(parsed: &ParsedUrl) -> Option<Segments> {
621625 let committish = parsed
622626 . hash
623627 . as_deref ( )
624- . map ( |h| h . strip_prefix ( '#' ) . unwrap_or ( h ) . to_string ( ) )
625- . filter ( |s | !s . is_empty ( ) ) ;
628+ . map ( |hash| hash . strip_prefix ( '#' ) . unwrap_or ( hash ) . to_string ( ) )
629+ . filter ( |committish | !committish . is_empty ( ) ) ;
626630 Some ( Segments { user, project, committish } )
627631}
628632
@@ -632,32 +636,32 @@ fn extract_gitlab(parsed: &ParsedUrl) -> Option<Segments> {
632636/// returning `None` at the call site). Pacquet keeps the input as-is on
633637/// malformed input — the affected URLs are caught elsewhere when the
634638/// downstream parse fails.
635- fn percent_decode ( s : & str ) -> String {
636- let mut out = String :: with_capacity ( s . len ( ) ) ;
637- let bytes = s . as_bytes ( ) ;
638- let mut i = 0 ;
639- while i < bytes. len ( ) {
640- if bytes[ i ] == b'%'
641- && i + 2 < bytes. len ( )
639+ fn percent_decode ( input : & str ) -> String {
640+ let mut out = String :: with_capacity ( input . len ( ) ) ;
641+ let bytes = input . as_bytes ( ) ;
642+ let mut idx = 0 ;
643+ while idx < bytes. len ( ) {
644+ if bytes[ idx ] == b'%'
645+ && idx + 2 < bytes. len ( )
642646 && let ( Some ( hi) , Some ( lo) ) =
643- ( ( bytes[ i + 1 ] as char ) . to_digit ( 16 ) , ( bytes[ i + 2 ] as char ) . to_digit ( 16 ) )
647+ ( ( bytes[ idx + 1 ] as char ) . to_digit ( 16 ) , ( bytes[ idx + 2 ] as char ) . to_digit ( 16 ) )
644648 {
645649 out. push ( ( hi * 16 + lo) as u8 as char ) ;
646- i += 3 ;
650+ idx += 3 ;
647651 continue ;
648652 }
649- out. push ( bytes[ i ] as char ) ;
650- i += 1 ;
653+ out. push ( bytes[ idx ] as char ) ;
654+ idx += 1 ;
651655 }
652656 out
653657}
654658
655659/// Match Node's `encodeURIComponent`. Percent-encode every byte
656660/// outside the safe ASCII set Node keeps unencoded:
657661/// `A-Z a-z 0-9 - _ . ! ~ * ' ( )`.
658- fn encode_uri_component ( s : & str ) -> String {
659- let mut out = String :: with_capacity ( s . len ( ) ) ;
660- for byte in s . bytes ( ) {
662+ fn encode_uri_component ( input : & str ) -> String {
663+ let mut out = String :: with_capacity ( input . len ( ) ) ;
664+ for byte in input . bytes ( ) {
661665 let safe = byte. is_ascii_alphanumeric ( )
662666 || matches ! ( byte, b'-' | b'_' | b'.' | b'!' | b'~' | b'*' | b'\'' | b'(' | b')' ) ;
663667 if safe {
@@ -745,7 +749,7 @@ mod tests {
745749 fn rejects_non_hosted ( ) {
746750 // Gitea / generic .git URLs are not recognised by hosted-git-info.
747751 assert ! (
748- HostedGit :: from_url( "https://gitea.osmocom.org/ttcn3/highlightjs-ttcn3.git" ) . is_none( )
752+ HostedGit :: from_url( "https://gitea.osmocom.org/ttcn3/highlightjs-ttcn3.git" ) . is_none( ) ,
749753 ) ;
750754 }
751755
@@ -767,7 +771,7 @@ mod tests {
767771 . expect ( "ok" ) ;
768772 assert_eq ! (
769773 h. shortcut( HostedOpts :: default ( ) ) ,
770- "github:zkochan/is-negative#163360a8d3ae6bee9524541043197ff356f8ed99"
774+ "github:zkochan/is-negative#163360a8d3ae6bee9524541043197ff356f8ed99" ,
771775 ) ;
772776 assert_eq ! ( h. shortcut( HostedGit :: no_committish( ) ) , "github:zkochan/is-negative" ) ;
773777 }
@@ -777,11 +781,11 @@ mod tests {
777781 let h = HostedGit :: from_url ( "zkochan/is-negative" ) . expect ( "ok" ) ;
778782 assert_eq ! (
779783 h. https( HostedOpts :: default ( ) ) . unwrap( ) ,
780- "git+https://github.com/zkochan/is-negative.git"
784+ "git+https://github.com/zkochan/is-negative.git" ,
781785 ) ;
782786 assert_eq ! (
783787 h. https( HostedGit :: no_committish_no_git_plus( ) ) . unwrap( ) ,
784- "https://github.com/zkochan/is-negative.git"
788+ "https://github.com/zkochan/is-negative.git" ,
785789 ) ;
786790 }
787791
@@ -791,11 +795,11 @@ mod tests {
791795 assert_eq ! ( h
. ssh
( HostedOpts :: default ( ) ) . unwrap
( ) , "[email protected] :foo/bar.git" ) ; 792796 assert_eq ! (
793797 h. sshurl( HostedOpts :: default ( ) ) . unwrap( ) ,
794- "git+ssh://[email protected] /foo/bar.git" 798+ "git+ssh://[email protected] /foo/bar.git" , 795799 ) ;
796800 assert_eq ! (
797801 h. sshurl( HostedGit :: no_committish( ) ) . unwrap( ) ,
798- "git+ssh://[email protected] /foo/bar.git" 802+ "git+ssh://[email protected] /foo/bar.git" , 799803 ) ;
800804 }
801805
@@ -805,7 +809,7 @@ mod tests {
805809 h. committish = Some ( "163360a8d3ae6bee9524541043197ff356f8ed99" . to_string ( ) ) ;
806810 assert_eq ! (
807811 h. tarball( HostedOpts :: default ( ) ) . unwrap( ) ,
808- "https://codeload.github.com/zkochan/is-negative/tar.gz/163360a8d3ae6bee9524541043197ff356f8ed99"
812+ "https://codeload.github.com/zkochan/is-negative/tar.gz/163360a8d3ae6bee9524541043197ff356f8ed99" ,
809813 ) ;
810814 }
811815
@@ -815,7 +819,7 @@ mod tests {
815819 h. committish = Some ( "abc123" . to_string ( ) ) ;
816820 assert_eq ! (
817821 h. tarball( HostedOpts :: default ( ) ) . unwrap( ) ,
818- "https://bitbucket.org/foo/bar/get/abc123.tar.gz"
822+ "https://bitbucket.org/foo/bar/get/abc123.tar.gz" ,
819823 ) ;
820824 }
821825
@@ -830,7 +834,7 @@ mod tests {
830834 assert ! ( !tarball. contains( "%2F" ) , "tarball must not contain `%2F`: {tarball}" ) ;
831835 assert_eq ! (
832836 tarball,
833- "https://gitlab.com/pnpmjs/git-resolver/-/archive/988c61e11dc8d9ca0b5580cb15291951812549dc/git-resolver-988c61e11dc8d9ca0b5580cb15291951812549dc.tar.gz"
837+ "https://gitlab.com/pnpmjs/git-resolver/-/archive/988c61e11dc8d9ca0b5580cb15291951812549dc/git-resolver-988c61e11dc8d9ca0b5580cb15291951812549dc.tar.gz" ,
834838 ) ;
835839 }
836840
@@ -845,7 +849,7 @@ mod tests {
845849 let h =
HostedGit :: from_url ( "git+https://0000000000000000000000000000000000000000:[email protected] /foo/bar.git" ) . expect ( "ok" ) ; 846850 assert_eq ! (
847851 h. https( HostedGit :: no_committish_no_git_plus( ) ) . unwrap( ) ,
848- "https://0000000000000000000000000000000000000000:[email protected] /foo/bar.git" 852+ "https://0000000000000000000000000000000000000000:[email protected] /foo/bar.git" , 849853 ) ;
850854 assert ! ( h. auth. is_some( ) ) ;
851855 }
0 commit comments