@@ -537,23 +537,63 @@ describe('prefix-based routing', () => {
537
537
) ;
538
538
} ) ;
539
539
540
- it ( 'redirects an invalid, upper-cased request for a localized route to the case-sensitive format' , ( ) => {
540
+ it ( 'redirects uppercase locale requests to case-sensitive defaults at the root' , ( ) => {
541
+ middlewareWithPathnames ( createMockRequest ( '/EN' , 'en' ) ) ;
542
+ expect ( MockedNextResponse . rewrite ) . not . toHaveBeenCalled ( ) ;
543
+ expect ( MockedNextResponse . next ) . not . toHaveBeenCalled ( ) ;
544
+ expect ( MockedNextResponse . redirect ) . toHaveBeenCalled ( ) ;
545
+ expect ( MockedNextResponse . redirect . mock . calls [ 0 ] [ 0 ] . toString ( ) ) . toBe (
546
+ 'http://localhost:3000/en/'
547
+ ) ;
548
+ } ) ;
549
+
550
+ it ( 'redirects uppercase locale requests to case-sensitive defaults for nested paths' , ( ) => {
551
+ middlewareWithPathnames ( createMockRequest ( '/EN/about' , 'en' ) ) ;
552
+ expect ( MockedNextResponse . rewrite ) . not . toHaveBeenCalled ( ) ;
553
+ expect ( MockedNextResponse . next ) . not . toHaveBeenCalled ( ) ;
554
+ expect ( MockedNextResponse . redirect ) . toHaveBeenCalled ( ) ;
555
+ expect ( MockedNextResponse . redirect . mock . calls [ 0 ] [ 0 ] . toString ( ) ) . toBe (
556
+ 'http://localhost:3000/en/about'
557
+ ) ;
558
+ } ) ;
559
+
560
+ it ( 'redirects uppercase locale requests for non-default locales at the root' , ( ) => {
541
561
middlewareWithPathnames ( createMockRequest ( '/DE-AT' , 'de-AT' ) ) ;
542
562
expect ( MockedNextResponse . rewrite ) . not . toHaveBeenCalled ( ) ;
543
563
expect ( MockedNextResponse . next ) . not . toHaveBeenCalled ( ) ;
544
564
expect ( MockedNextResponse . redirect ) . toHaveBeenCalled ( ) ;
545
565
expect ( MockedNextResponse . redirect . mock . calls [ 0 ] [ 0 ] . toString ( ) ) . toBe (
546
- 'http://localhost:3000/de-AT'
566
+ 'http://localhost:3000/de-AT/ '
547
567
) ;
548
568
} ) ;
549
569
550
- it ( 'redirects an invalid, lower-cased request for a localized route to the case-sensitive format' , ( ) => {
570
+ it ( 'redirects uppercase locale requests for non-default locales and nested paths' , ( ) => {
571
+ middlewareWithPathnames ( createMockRequest ( '/DE-AT/ueber' , 'de-AT' ) ) ;
572
+ expect ( MockedNextResponse . rewrite ) . not . toHaveBeenCalled ( ) ;
573
+ expect ( MockedNextResponse . next ) . not . toHaveBeenCalled ( ) ;
574
+ expect ( MockedNextResponse . redirect ) . toHaveBeenCalled ( ) ;
575
+ expect ( MockedNextResponse . redirect . mock . calls [ 0 ] [ 0 ] . toString ( ) ) . toBe (
576
+ 'http://localhost:3000/de-AT/ueber'
577
+ ) ;
578
+ } ) ;
579
+
580
+ it ( 'redirects lowercase locale requests for non-default locales to case-sensitive format at the root' , ( ) => {
551
581
middlewareWithPathnames ( createMockRequest ( '/de-at' , 'de-AT' ) ) ;
552
582
expect ( MockedNextResponse . rewrite ) . not . toHaveBeenCalled ( ) ;
553
583
expect ( MockedNextResponse . next ) . not . toHaveBeenCalled ( ) ;
554
584
expect ( MockedNextResponse . redirect ) . toHaveBeenCalled ( ) ;
555
585
expect ( MockedNextResponse . redirect . mock . calls [ 0 ] [ 0 ] . toString ( ) ) . toBe (
556
- 'http://localhost:3000/de-AT'
586
+ 'http://localhost:3000/de-AT/'
587
+ ) ;
588
+ } ) ;
589
+
590
+ it ( 'redirects lowercase locale requests for non-default locales to case-sensitive format for nested paths' , ( ) => {
591
+ middlewareWithPathnames ( createMockRequest ( '/de-at/ueber' , 'de-AT' ) ) ;
592
+ expect ( MockedNextResponse . rewrite ) . not . toHaveBeenCalled ( ) ;
593
+ expect ( MockedNextResponse . next ) . not . toHaveBeenCalled ( ) ;
594
+ expect ( MockedNextResponse . redirect ) . toHaveBeenCalled ( ) ;
595
+ expect ( MockedNextResponse . redirect . mock . calls [ 0 ] [ 0 ] . toString ( ) ) . toBe (
596
+ 'http://localhost:3000/de-AT/ueber'
557
597
) ;
558
598
} ) ;
559
599
@@ -976,7 +1016,7 @@ describe('prefix-based routing', () => {
976
1016
describe ( 'localePrefix: never' , ( ) => {
977
1017
const middleware = createIntlMiddleware ( {
978
1018
defaultLocale : 'en' ,
979
- locales : [ 'en' , 'de' ] ,
1019
+ locales : [ 'en' , 'de' , 'de-AT' ] ,
980
1020
localePrefix : 'never'
981
1021
} ) ;
982
1022
@@ -1074,6 +1114,36 @@ describe('prefix-based routing', () => {
1074
1114
) ;
1075
1115
} ) ;
1076
1116
1117
+ it ( 'redirects requests with uppercase default locale in a nested path' , ( ) => {
1118
+ middleware ( createMockRequest ( '/EN/list' ) ) ;
1119
+ expect ( MockedNextResponse . rewrite ) . not . toHaveBeenCalled ( ) ;
1120
+ expect ( MockedNextResponse . next ) . not . toHaveBeenCalled ( ) ;
1121
+ expect ( MockedNextResponse . redirect ) . toHaveBeenCalled ( ) ;
1122
+ expect ( MockedNextResponse . redirect . mock . calls [ 0 ] [ 0 ] . toString ( ) ) . toBe (
1123
+ 'http://localhost:3000/list'
1124
+ ) ;
1125
+ } ) ;
1126
+
1127
+ it ( 'redirects requests with uppercase non-default locale in a nested path' , ( ) => {
1128
+ middleware ( createMockRequest ( '/DE-AT/list' ) ) ;
1129
+ expect ( MockedNextResponse . rewrite ) . not . toHaveBeenCalled ( ) ;
1130
+ expect ( MockedNextResponse . next ) . not . toHaveBeenCalled ( ) ;
1131
+ expect ( MockedNextResponse . redirect ) . toHaveBeenCalled ( ) ;
1132
+ expect ( MockedNextResponse . redirect . mock . calls [ 0 ] [ 0 ] . toString ( ) ) . toBe (
1133
+ 'http://localhost:3000/list'
1134
+ ) ;
1135
+ } ) ;
1136
+
1137
+ it ( 'redirects requests with lowercase non-default locale in a nested path' , ( ) => {
1138
+ middleware ( createMockRequest ( '/de-at/list' ) ) ;
1139
+ expect ( MockedNextResponse . rewrite ) . not . toHaveBeenCalled ( ) ;
1140
+ expect ( MockedNextResponse . next ) . not . toHaveBeenCalled ( ) ;
1141
+ expect ( MockedNextResponse . redirect ) . toHaveBeenCalled ( ) ;
1142
+ expect ( MockedNextResponse . redirect . mock . calls [ 0 ] [ 0 ] . toString ( ) ) . toBe (
1143
+ 'http://localhost:3000/list'
1144
+ ) ;
1145
+ } ) ;
1146
+
1077
1147
it ( 'rewrites requests for the root if a cookie exists with a non-default locale' , ( ) => {
1078
1148
middleware ( createMockRequest ( '/' , 'en' , 'http://localhost:3000' , 'de' ) ) ;
1079
1149
expect ( MockedNextResponse . next ) . not . toHaveBeenCalled ( ) ;
0 commit comments