@@ -21,15 +21,24 @@ describe("getRequestURL", () => {
2121 expect ( getRequestURL ( req ) ) . toBe ( "/path%20with%20spaces" ) ;
2222 } ) ;
2323
24- it ( "should return encoded req.url when middleware (e.g. connect-history-api-fallback) modified it" , ( ) => {
24+ it ( "should return req.originalUrl for URLs with reserved characters" , ( ) => {
25+ // Fastify partially decodes: %20 → space, but %26 stays as %26
26+ const req = {
27+ url : "/test %26 test %26 %20.txt" ,
28+ originalUrl : "/test%20%26%20test%20%26%20%2520.txt" ,
29+ } ;
30+ expect ( getRequestURL ( req ) ) . toBe ( "/test%20%26%20test%20%26%20%2520.txt" ) ;
31+ } ) ;
32+
33+ it ( "should return req.url when middleware (e.g. connect-history-api-fallback) modified it" , ( ) => {
2534 // Middleware changed req.url to a different path
2635 const req = { url : "/index.html" , originalUrl : "/path%20with%20spaces" } ;
2736 expect ( getRequestURL ( req ) ) . toBe ( "/index.html" ) ;
2837 } ) ;
2938
30- it ( "should encode req.url when middleware sets a path with special chars" , ( ) => {
39+ it ( "should return req.url when middleware sets a path with special chars" , ( ) => {
3140 const req = { url : "/new path" , originalUrl : "/old%20path" } ;
32- expect ( getRequestURL ( req ) ) . toBe ( "/new%20path " ) ;
41+ expect ( getRequestURL ( req ) ) . toBe ( "/new path " ) ;
3342 } ) ;
3443
3544 it ( "should preserve query string from modified req.url" , ( ) => {
@@ -39,5 +48,22 @@ describe("getRequestURL", () => {
3948 } ;
4049 expect ( getRequestURL ( req ) ) . toBe ( "/index.html?redirect=/other" ) ;
4150 } ) ;
51+
52+ it ( "should return req.originalUrl when req.url equals req.originalUrl (Express)" , ( ) => {
53+ const req = {
54+ url : "/path%20foo" ,
55+ originalUrl : "/path%20foo" ,
56+ } ;
57+ expect ( getRequestURL ( req ) ) . toBe ( "/path%20foo" ) ;
58+ } ) ;
59+
60+ it ( "should handle malformed percent-encoding in originalUrl gracefully" , ( ) => {
61+ // decodeURI would throw on malformed sequences
62+ const req = {
63+ url : "/foo" ,
64+ originalUrl : "/%GG%bad" ,
65+ } ;
66+ expect ( getRequestURL ( req ) ) . toBe ( "/foo" ) ;
67+ } ) ;
4268 } ) ;
4369} ) ;
0 commit comments