@@ -617,21 +617,22 @@ fn parse_extras(cursor: &mut Cursor) -> Result<Vec<ExtraName>, Pep508Error> {
617
617
let Some ( bracket_pos) = cursor. eat_char ( '[' ) else {
618
618
return Ok ( vec ! [ ] ) ;
619
619
} ;
620
+ cursor. eat_whitespace ( ) ;
621
+
620
622
let mut extras = Vec :: new ( ) ;
621
623
let mut is_first_iteration = true ;
622
624
623
625
loop {
624
- cursor. eat_whitespace ( ) ;
625
-
626
- // End of the extras section
626
+ // End of the extras section. (Empty extras are allowed.)
627
627
if let Some ( ']' ) = cursor. peek_char ( ) {
628
628
cursor. next ( ) ;
629
629
break ;
630
630
}
631
631
632
+
632
633
// Comma separator
633
634
match ( cursor. peek ( ) , is_first_iteration) {
634
- // For the first iteration, we don't expect a comma
635
+ // For the first iteration, we don't expect a comma.
635
636
( Some ( ( pos, ',' ) ) , true ) => {
636
637
return Err ( Pep508Error {
637
638
message : Pep508ErrorSource :: String (
@@ -642,7 +643,7 @@ fn parse_extras(cursor: &mut Cursor) -> Result<Vec<ExtraName>, Pep508Error> {
642
643
input : cursor. to_string ( ) ,
643
644
} ) ;
644
645
}
645
- // For the other iterations, the comma is required
646
+ // For the other iterations, the comma is required.
646
647
( Some ( ( _, ',' ) ) , false ) => {
647
648
cursor. next ( ) ;
648
649
}
@@ -672,7 +673,7 @@ fn parse_extras(cursor: &mut Cursor) -> Result<Vec<ExtraName>, Pep508Error> {
672
673
input : cursor. to_string ( ) ,
673
674
} ;
674
675
675
- // First char of the identifier
676
+ // First char of the identifier.
676
677
match cursor. next ( ) {
677
678
// letterOrDigit
678
679
Some ( ( _, alphanumeric @ ( 'a' ..='z' | 'A' ..='Z' | '0' ..='9' ) ) ) => {
@@ -712,6 +713,7 @@ fn parse_extras(cursor: &mut Cursor) -> Result<Vec<ExtraName>, Pep508Error> {
712
713
} ;
713
714
// wsp* after the identifier
714
715
cursor. eat_whitespace ( ) ;
716
+
715
717
// Add the parsed extra
716
718
extras. push (
717
719
ExtraName :: new ( buffer) . expect ( "`ExtraName` validation should match PEP 508 parsing" ) ,
@@ -1258,6 +1260,18 @@ mod tests {
1258
1260
) ;
1259
1261
}
1260
1262
1263
+ #[ test]
1264
+ fn error_extras_illegal_start3 ( ) {
1265
+ assert_err (
1266
+ "black[,]" ,
1267
+ indoc ! { "
1268
+ Expected either alphanumerical character (starting the extra name) or ']' (ending the extras section), found ','
1269
+ black[,]
1270
+ ^"
1271
+ } ,
1272
+ ) ;
1273
+ }
1274
+
1261
1275
#[ test]
1262
1276
fn error_extras_illegal_character ( ) {
1263
1277
assert_err (
0 commit comments