@@ -3,6 +3,7 @@ use nfa::NFA;
3
3
use std:: cmp:: Ordering ;
4
4
use std:: collections:: btree_map;
5
5
use std:: collections:: BTreeMap ;
6
+ use std:: collections:: HashSet ;
6
7
use std:: ops:: Index ;
7
8
8
9
pub mod nfa;
@@ -173,6 +174,12 @@ impl<T> Router<T> {
173
174
metadata. statics += 1 ;
174
175
}
175
176
}
177
+ let mut hashes = HashSet :: new ( ) ;
178
+ for name in metadata. param_names . iter ( ) {
179
+ if !hashes. insert ( name. to_string ( ) ) {
180
+ panic ! ( "Duplicate name '{}' in route {}" , name. to_string( ) , & route) ;
181
+ }
182
+ }
176
183
177
184
nfa. acceptance ( state) ;
178
185
nfa. metadata ( state, metadata) ;
@@ -362,6 +369,41 @@ fn unnamed_parameters() {
362
369
assert_eq ! ( m. params, params( "bar" , "test" ) ) ;
363
370
}
364
371
372
+ #[ test]
373
+ #[ should_panic]
374
+ fn duplicate_named_parameter ( ) {
375
+ let mut router = Router :: new ( ) ;
376
+ router. add ( "/foo/:bar/:bar" , "test" . to_string ( ) ) ;
377
+ }
378
+
379
+ #[ test]
380
+ #[ should_panic]
381
+ fn duplicate_star_parameter ( ) {
382
+ let mut router = Router :: new ( ) ;
383
+ router. add ( "/foo/*bar/*bar" , "test" . to_string ( ) ) ;
384
+ }
385
+
386
+ #[ test]
387
+ #[ should_panic]
388
+ fn duplicate_mixed_parameter ( ) {
389
+ let mut router = Router :: new ( ) ;
390
+ router. add ( "/foo/*bar/:bar" , "test" . to_string ( ) ) ;
391
+ }
392
+
393
+ #[ test]
394
+ #[ should_panic]
395
+ fn duplicate_mixed_reversed_parameter ( ) {
396
+ let mut router = Router :: new ( ) ;
397
+ router. add ( "/foo/:bar/*bar" , "test" . to_string ( ) ) ;
398
+ }
399
+
400
+ #[ test]
401
+ #[ should_panic]
402
+ fn duplicate_separated_parameter ( ) {
403
+ let mut router = Router :: new ( ) ;
404
+ router. add ( "/foo/:bar/bleg/:bar" , "test" . to_string ( ) ) ;
405
+ }
406
+
365
407
#[ allow( dead_code) ]
366
408
fn params ( key : & str , val : & str ) -> Params {
367
409
let mut map = Params :: new ( ) ;
0 commit comments