@@ -4494,7 +4494,7 @@ describe("a router", () => {
4494
4494
) ;
4495
4495
} ) ;
4496
4496
4497
- it ( "returns a 400 error if binary data is attempted to be submitted using formMethod= GET" , async ( ) => {
4497
+ it ( "url-encodes File names on GET submissions " , async ( ) => {
4498
4498
let t = setup ( {
4499
4499
routes : TASK_ROUTES ,
4500
4500
initialEntries : [ "/" ] ,
@@ -4511,26 +4511,17 @@ describe("a router", () => {
4511
4511
"blob" ,
4512
4512
new Blob ( [ "<h1>Some html file contents</h1>" ] , {
4513
4513
type : "text/html" ,
4514
- } )
4514
+ } ) ,
4515
+ "blob.html"
4515
4516
) ;
4516
4517
4517
- await t . navigate ( "/tasks" , {
4518
+ let A = await t . navigate ( "/tasks" , {
4518
4519
formMethod : "get" ,
4519
4520
formData : formData ,
4520
4521
} ) ;
4521
- expect ( t . router . state . navigation . state ) . toBe ( "idle" ) ;
4522
- expect ( t . router . state . location ) . toMatchObject ( {
4523
- pathname : "/tasks" ,
4524
- search : "" ,
4525
- } ) ;
4526
- expect ( t . router . state . errors ) . toEqual ( {
4527
- tasks : new ErrorResponse (
4528
- 400 ,
4529
- "Bad Request" ,
4530
- new Error ( "Cannot submit binary form data using GET" ) ,
4531
- true
4532
- ) ,
4533
- } ) ;
4522
+ let params = new URL ( A . loaders . tasks . stub . mock . calls [ 0 ] [ 0 ] . request . url )
4523
+ . searchParams ;
4524
+ expect ( params . get ( "blob" ) ) . toEqual ( "blob.html" ) ;
4534
4525
} ) ;
4535
4526
4536
4527
it ( "returns a 405 error if attempting to submit with method=HEAD" , async ( ) => {
@@ -4612,61 +4603,6 @@ describe("a router", () => {
4612
4603
) ,
4613
4604
} ) ;
4614
4605
} ) ;
4615
-
4616
- it ( "runs loaders above the boundary for 400 errors if binary data is attempted to be submitted using formMethod=GET" , async ( ) => {
4617
- let t = setup ( {
4618
- routes : [
4619
- {
4620
- id : "index" ,
4621
- index : true ,
4622
- } ,
4623
- {
4624
- id : "parent" ,
4625
- path : "parent" ,
4626
- loader : true ,
4627
- children : [
4628
- {
4629
- id : "child" ,
4630
- path : "child" ,
4631
- loader : true ,
4632
- hasErrorBoundary : true ,
4633
- } ,
4634
- ] ,
4635
- } ,
4636
- ] ,
4637
- initialEntries : [ "/" ] ,
4638
- } ) ;
4639
-
4640
- let formData = new FormData ( ) ;
4641
- formData . append (
4642
- "blob" ,
4643
- new Blob ( [ "<h1>Some html file contents</h1>" ] , {
4644
- type : "text/html" ,
4645
- } )
4646
- ) ;
4647
-
4648
- let A = await t . navigate ( "/parent/child" , {
4649
- formMethod : "get" ,
4650
- formData : formData ,
4651
- } ) ;
4652
- expect ( t . router . state . navigation . state ) . toBe ( "loading" ) ;
4653
- expect ( t . router . state . errors ) . toEqual ( null ) ;
4654
-
4655
- await A . loaders . parent . resolve ( "PARENT" ) ;
4656
- expect ( A . loaders . child . stub ) . not . toHaveBeenCalled ( ) ;
4657
- expect ( t . router . state . navigation . state ) . toBe ( "idle" ) ;
4658
- expect ( t . router . state . loaderData ) . toEqual ( {
4659
- parent : "PARENT" ,
4660
- } ) ;
4661
- expect ( t . router . state . errors ) . toEqual ( {
4662
- child : new ErrorResponse (
4663
- 400 ,
4664
- "Bad Request" ,
4665
- new Error ( "Cannot submit binary form data using GET" ) ,
4666
- true
4667
- ) ,
4668
- } ) ;
4669
- } ) ;
4670
4606
} ) ;
4671
4607
4672
4608
describe ( "data loading (new)" , ( ) => {
@@ -5711,6 +5647,37 @@ describe("a router", () => {
5711
5647
) ;
5712
5648
} ) ;
5713
5649
5650
+ it ( "url-encodes File names on x-www-form-urlencoded submissions" , async ( ) => {
5651
+ let t = setup ( {
5652
+ routes : [
5653
+ {
5654
+ id : "root" ,
5655
+ path : "/" ,
5656
+ action : true ,
5657
+ } ,
5658
+ ] ,
5659
+ initialEntries : [ "/" ] ,
5660
+ hydrationData : {
5661
+ loaderData : {
5662
+ root : "ROOT_DATA" ,
5663
+ } ,
5664
+ } ,
5665
+ } ) ;
5666
+
5667
+ let fd = new FormData ( ) ;
5668
+ fd . append ( "key" , "value" ) ;
5669
+ fd . append ( "file" , new Blob ( [ "1" , "2" , "3" ] ) , "file.txt" ) ;
5670
+
5671
+ let A = await t . navigate ( "/" , {
5672
+ formMethod : "post" ,
5673
+ formEncType : "application/x-www-form-urlencoded" ,
5674
+ formData : fd ,
5675
+ } ) ;
5676
+
5677
+ let req = A . actions . root . stub . mock . calls [ 0 ] [ 0 ] . request . clone ( ) ;
5678
+ expect ( ( await req . formData ( ) ) . get ( "file" ) ) . toEqual ( "file.txt" ) ;
5679
+ } ) ;
5680
+
5714
5681
it ( "races actions and loaders against abort signals" , async ( ) => {
5715
5682
let loaderDfd = createDeferred ( ) ;
5716
5683
let actionDfd = createDeferred ( ) ;
@@ -10192,6 +10159,7 @@ describe("a router", () => {
10192
10159
{
10193
10160
id : "b" ,
10194
10161
path : "b" ,
10162
+ loader : true ,
10195
10163
} ,
10196
10164
] ,
10197
10165
} ,
@@ -10230,12 +10198,11 @@ describe("a router", () => {
10230
10198
// Perform an invalid navigation to /parent/b which will be handled
10231
10199
// using parent's error boundary. Parent's deferred should be left alone
10232
10200
// while A's should be cancelled since they will no longer be rendered
10233
- let formData = new FormData ( ) ;
10234
- formData . append ( "file" , new Blob ( [ "1" , "2" ] ) , "file.txt" ) ;
10235
- await t . navigate ( "/parent/b" , {
10236
- formMethod : "get" ,
10237
- formData,
10238
- } ) ;
10201
+ let B = await t . navigate ( "/parent/b" ) ;
10202
+ await B . loaders . b . reject (
10203
+ new Response ( "broken" , { status : 400 , statusText : "Bad Request" } )
10204
+ ) ;
10205
+
10239
10206
// Navigation completes immediately with an error at the boundary
10240
10207
expect ( t . router . state . loaderData ) . toEqual ( {
10241
10208
parent : {
@@ -10244,12 +10211,7 @@ describe("a router", () => {
10244
10211
} ,
10245
10212
} ) ;
10246
10213
expect ( t . router . state . errors ) . toEqual ( {
10247
- parent : new ErrorResponse (
10248
- 400 ,
10249
- "Bad Request" ,
10250
- new Error ( "Cannot submit binary form data using GET" ) ,
10251
- true
10252
- ) ,
10214
+ parent : new ErrorResponse ( 400 , "Bad Request" , "broken" , false ) ,
10253
10215
} ) ;
10254
10216
10255
10217
await parentDfd . resolve ( "Yep!" ) ;
@@ -10330,12 +10292,11 @@ describe("a router", () => {
10330
10292
// Perform an invalid navigation to /b/child which should cancel all
10331
10293
// pending deferred's since nothing is reused. It should not call bChild's
10332
10294
// loader since it's below the boundary but should call b's loader.
10333
- let formData = new FormData ( ) ;
10334
- formData . append ( "file" , new Blob ( [ "1" , "2" ] ) , "file.txt" ) ;
10335
- let B = await t . navigate ( "/b/child" , {
10336
- formMethod : "get" ,
10337
- formData,
10338
- } ) ;
10295
+ let B = await t . navigate ( "/b/child" ) ;
10296
+
10297
+ await B . loaders . bChild . reject (
10298
+ new Response ( "broken" , { status : 400 , statusText : "Bad Request" } )
10299
+ ) ;
10339
10300
10340
10301
// Both should be cancelled
10341
10302
await aDfd . resolve ( "Nope!" ) ;
@@ -10356,14 +10317,8 @@ describe("a router", () => {
10356
10317
b : "B LOADER" ,
10357
10318
} ) ;
10358
10319
expect ( t . router . state . errors ) . toEqual ( {
10359
- bChild : new ErrorResponse (
10360
- 400 ,
10361
- "Bad Request" ,
10362
- new Error ( "Cannot submit binary form data using GET" ) ,
10363
- true
10364
- ) ,
10320
+ bChild : new ErrorResponse ( 400 , "Bad Request" , "broken" , false ) ,
10365
10321
} ) ;
10366
- expect ( B . loaders . bChild . stub ) . not . toHaveBeenCalled ( ) ;
10367
10322
} ) ;
10368
10323
10369
10324
it ( "does not cancel pending deferreds on hash change only navigations" , async ( ) => {
0 commit comments