@@ -130,15 +130,23 @@ impl TryFrom<&'_ PackageId> for Crate {
130
130
Some ( SourceKind :: Git ( rev) ) => {
131
131
if let Some ( url) = package_id. url ( ) {
132
132
if url. domain ( ) == Some ( "github.com" ) {
133
- Ok ( Crate :: GitHub ( GitHubRepo {
134
- org : url
135
- . path_segments ( )
136
- . and_then ( |mut path| path. next ( ) )
137
- . unwrap_or_default ( )
138
- . to_string ( ) ,
139
- name : package_id. name ( ) . to_string ( ) ,
140
- sha : rev. pretty_ref ( false ) . map ( |rev| rev. to_string ( ) ) ,
141
- } ) )
133
+ if let Some ( mut path) = url. path_segments ( ) {
134
+ let Some ( org) = path. next ( ) else {
135
+ bail ! ( "Github URL path is too short" )
136
+ } ;
137
+
138
+ let Some ( repo_name) = path. next ( ) else {
139
+ bail ! ( "Github URL path is too short" )
140
+ } ;
141
+
142
+ Ok ( Crate :: GitHub ( GitHubRepo {
143
+ org : org. to_string ( ) ,
144
+ name : repo_name. to_string ( ) ,
145
+ sha : rev. pretty_ref ( false ) . map ( |rev| rev. to_string ( ) ) ,
146
+ } ) )
147
+ } else {
148
+ bail ! ( "Github Git URL doesn't have a valid path" )
149
+ }
142
150
} else {
143
151
Ok ( Crate :: Git ( GitRepo {
144
152
url : url. to_string ( ) ,
@@ -179,15 +187,23 @@ impl TryFrom<&'_ PackageId> for Crate {
179
187
Some ( url) => match url. scheme ( ) {
180
188
"http" | "https" | "git" | "ssh" => {
181
189
if url. domain ( ) == Some ( "github.com" ) {
182
- Ok ( Crate :: GitHub ( GitHubRepo {
183
- org : url
184
- . path_segments ( )
185
- . and_then ( |mut path| path. next ( ) )
186
- . unwrap_or_default ( )
187
- . to_string ( ) ,
188
- name : package_id. name ( ) . to_string ( ) ,
189
- sha : None ,
190
- } ) )
190
+ if let Some ( mut path) = url. path_segments ( ) {
191
+ let Some ( org) = path. next ( ) else {
192
+ bail ! ( "Github URL path is too short" )
193
+ } ;
194
+
195
+ let Some ( repo_name) = path. next ( ) else {
196
+ bail ! ( "Github URL path is too short" )
197
+ } ;
198
+
199
+ Ok ( Crate :: GitHub ( GitHubRepo {
200
+ org : org. to_string ( ) ,
201
+ name : repo_name. to_string ( ) ,
202
+ sha : None ,
203
+ } ) )
204
+ } else {
205
+ bail ! ( "Github Git URL doesn't have a valid path" )
206
+ }
191
207
} else {
192
208
Ok ( Crate :: Git ( GitRepo {
193
209
url : url. to_string ( ) ,
0 commit comments