@@ -4493,7 +4493,7 @@ describe("a router", () => {
4493
4493
) ;
4494
4494
} ) ;
4495
4495
4496
- it ( "returns a 400 error if binary data is attempted to be submitted using formMethod= GET" , async ( ) => {
4496
+ it ( "url-encodes File names on GET submissions " , async ( ) => {
4497
4497
let t = setup ( {
4498
4498
routes : TASK_ROUTES ,
4499
4499
initialEntries : [ "/" ] ,
@@ -4510,26 +4510,17 @@ describe("a router", () => {
4510
4510
"blob" ,
4511
4511
new Blob ( [ "<h1>Some html file contents</h1>" ] , {
4512
4512
type : "text/html" ,
4513
- } )
4513
+ } ) ,
4514
+ "blob.html"
4514
4515
) ;
4515
4516
4516
- await t . navigate ( "/tasks" , {
4517
+ let A = await t . navigate ( "/tasks" , {
4517
4518
formMethod : "get" ,
4518
4519
formData : formData ,
4519
4520
} ) ;
4520
- expect ( t . router . state . navigation . state ) . toBe ( "idle" ) ;
4521
- expect ( t . router . state . location ) . toMatchObject ( {
4522
- pathname : "/tasks" ,
4523
- search : "" ,
4524
- } ) ;
4525
- expect ( t . router . state . errors ) . toEqual ( {
4526
- tasks : new ErrorResponse (
4527
- 400 ,
4528
- "Bad Request" ,
4529
- new Error ( "Cannot submit binary form data using GET" ) ,
4530
- true
4531
- ) ,
4532
- } ) ;
4521
+ let params = new URL ( A . loaders . tasks . stub . mock . calls [ 0 ] [ 0 ] . request . url )
4522
+ . searchParams ;
4523
+ expect ( params . get ( "blob" ) ) . toEqual ( "blob.html" ) ;
4533
4524
} ) ;
4534
4525
4535
4526
it ( "returns a 405 error if attempting to submit with method=HEAD" , async ( ) => {
@@ -4611,61 +4602,6 @@ describe("a router", () => {
4611
4602
) ,
4612
4603
} ) ;
4613
4604
} ) ;
4614
-
4615
- it ( "runs loaders above the boundary for 400 errors if binary data is attempted to be submitted using formMethod=GET" , async ( ) => {
4616
- let t = setup ( {
4617
- routes : [
4618
- {
4619
- id : "index" ,
4620
- index : true ,
4621
- } ,
4622
- {
4623
- id : "parent" ,
4624
- path : "parent" ,
4625
- loader : true ,
4626
- children : [
4627
- {
4628
- id : "child" ,
4629
- path : "child" ,
4630
- loader : true ,
4631
- hasErrorBoundary : true ,
4632
- } ,
4633
- ] ,
4634
- } ,
4635
- ] ,
4636
- initialEntries : [ "/" ] ,
4637
- } ) ;
4638
-
4639
- let formData = new FormData ( ) ;
4640
- formData . append (
4641
- "blob" ,
4642
- new Blob ( [ "<h1>Some html file contents</h1>" ] , {
4643
- type : "text/html" ,
4644
- } )
4645
- ) ;
4646
-
4647
- let A = await t . navigate ( "/parent/child" , {
4648
- formMethod : "get" ,
4649
- formData : formData ,
4650
- } ) ;
4651
- expect ( t . router . state . navigation . state ) . toBe ( "loading" ) ;
4652
- expect ( t . router . state . errors ) . toEqual ( null ) ;
4653
-
4654
- await A . loaders . parent . resolve ( "PARENT" ) ;
4655
- expect ( A . loaders . child . stub ) . not . toHaveBeenCalled ( ) ;
4656
- expect ( t . router . state . navigation . state ) . toBe ( "idle" ) ;
4657
- expect ( t . router . state . loaderData ) . toEqual ( {
4658
- parent : "PARENT" ,
4659
- } ) ;
4660
- expect ( t . router . state . errors ) . toEqual ( {
4661
- child : new ErrorResponse (
4662
- 400 ,
4663
- "Bad Request" ,
4664
- new Error ( "Cannot submit binary form data using GET" ) ,
4665
- true
4666
- ) ,
4667
- } ) ;
4668
- } ) ;
4669
4605
} ) ;
4670
4606
4671
4607
describe ( "data loading (new)" , ( ) => {
@@ -5710,6 +5646,37 @@ describe("a router", () => {
5710
5646
) ;
5711
5647
} ) ;
5712
5648
5649
+ it ( "url-encodes File names on x-www-form-urlencoded submissions" , async ( ) => {
5650
+ let t = setup ( {
5651
+ routes : [
5652
+ {
5653
+ id : "root" ,
5654
+ path : "/" ,
5655
+ action : true ,
5656
+ } ,
5657
+ ] ,
5658
+ initialEntries : [ "/" ] ,
5659
+ hydrationData : {
5660
+ loaderData : {
5661
+ root : "ROOT_DATA" ,
5662
+ } ,
5663
+ } ,
5664
+ } ) ;
5665
+
5666
+ let fd = new FormData ( ) ;
5667
+ fd . append ( "key" , "value" ) ;
5668
+ fd . append ( "file" , new Blob ( [ "1" , "2" , "3" ] ) , "file.txt" ) ;
5669
+
5670
+ let A = await t . navigate ( "/" , {
5671
+ formMethod : "post" ,
5672
+ formEncType : "application/x-www-form-urlencoded" ,
5673
+ formData : fd ,
5674
+ } ) ;
5675
+
5676
+ let req = A . actions . root . stub . mock . calls [ 0 ] [ 0 ] . request . clone ( ) ;
5677
+ expect ( ( await req . formData ( ) ) . get ( "file" ) ) . toEqual ( "file.txt" ) ;
5678
+ } ) ;
5679
+
5713
5680
it ( "races actions and loaders against abort signals" , async ( ) => {
5714
5681
let loaderDfd = createDeferred ( ) ;
5715
5682
let actionDfd = createDeferred ( ) ;
@@ -9909,6 +9876,7 @@ describe("a router", () => {
9909
9876
{
9910
9877
id : "b" ,
9911
9878
path : "b" ,
9879
+ loader : true ,
9912
9880
} ,
9913
9881
] ,
9914
9882
} ,
@@ -9947,12 +9915,11 @@ describe("a router", () => {
9947
9915
// Perform an invalid navigation to /parent/b which will be handled
9948
9916
// using parent's error boundary. Parent's deferred should be left alone
9949
9917
// while A's should be cancelled since they will no longer be rendered
9950
- let formData = new FormData ( ) ;
9951
- formData . append ( "file" , new Blob ( [ "1" , "2" ] ) , "file.txt" ) ;
9952
- await t . navigate ( "/parent/b" , {
9953
- formMethod : "get" ,
9954
- formData,
9955
- } ) ;
9918
+ let B = await t . navigate ( "/parent/b" ) ;
9919
+ await B . loaders . b . reject (
9920
+ new Response ( "broken" , { status : 400 , statusText : "Bad Request" } )
9921
+ ) ;
9922
+
9956
9923
// Navigation completes immediately with an error at the boundary
9957
9924
expect ( t . router . state . loaderData ) . toEqual ( {
9958
9925
parent : {
@@ -9961,12 +9928,7 @@ describe("a router", () => {
9961
9928
} ,
9962
9929
} ) ;
9963
9930
expect ( t . router . state . errors ) . toEqual ( {
9964
- parent : new ErrorResponse (
9965
- 400 ,
9966
- "Bad Request" ,
9967
- new Error ( "Cannot submit binary form data using GET" ) ,
9968
- true
9969
- ) ,
9931
+ parent : new ErrorResponse ( 400 , "Bad Request" , "broken" , false ) ,
9970
9932
} ) ;
9971
9933
9972
9934
await parentDfd . resolve ( "Yep!" ) ;
@@ -10047,12 +10009,11 @@ describe("a router", () => {
10047
10009
// Perform an invalid navigation to /b/child which should cancel all
10048
10010
// pending deferred's since nothing is reused. It should not call bChild's
10049
10011
// loader since it's below the boundary but should call b's loader.
10050
- let formData = new FormData ( ) ;
10051
- formData . append ( "file" , new Blob ( [ "1" , "2" ] ) , "file.txt" ) ;
10052
- let B = await t . navigate ( "/b/child" , {
10053
- formMethod : "get" ,
10054
- formData,
10055
- } ) ;
10012
+ let B = await t . navigate ( "/b/child" ) ;
10013
+
10014
+ await B . loaders . bChild . reject (
10015
+ new Response ( "broken" , { status : 400 , statusText : "Bad Request" } )
10016
+ ) ;
10056
10017
10057
10018
// Both should be cancelled
10058
10019
await aDfd . resolve ( "Nope!" ) ;
@@ -10073,14 +10034,8 @@ describe("a router", () => {
10073
10034
b : "B LOADER" ,
10074
10035
} ) ;
10075
10036
expect ( t . router . state . errors ) . toEqual ( {
10076
- bChild : new ErrorResponse (
10077
- 400 ,
10078
- "Bad Request" ,
10079
- new Error ( "Cannot submit binary form data using GET" ) ,
10080
- true
10081
- ) ,
10037
+ bChild : new ErrorResponse ( 400 , "Bad Request" , "broken" , false ) ,
10082
10038
} ) ;
10083
- expect ( B . loaders . bChild . stub ) . not . toHaveBeenCalled ( ) ;
10084
10039
} ) ;
10085
10040
10086
10041
it ( "does not cancel pending deferreds on hash change only navigations" , async ( ) => {
0 commit comments