File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -66,6 +66,14 @@ class MockInterceptor {
6666 if ( typeof opts . method === 'undefined' ) {
6767 throw new InvalidArgumentError ( 'opts.method must be defined' )
6868 }
69+ // See https://github.com/nodejs/undici/issues/1245
70+ // As per RFC 3986, clients are not supposed to send URI
71+ // fragments to servers when they retrieve a document,
72+ if ( typeof opts . path === 'string' ) {
73+ // Matches https://github.com/nodejs/undici/blob/main/lib/fetch/index.js#L1811
74+ const parsedURL = new URL ( opts . path , 'data://' )
75+ opts . path = parsedURL . pathname + parsedURL . search
76+ }
6977
7078 this [ kDispatchKey ] = buildKey ( opts )
7179 this [ kDispatches ] = mockDispatches
Original file line number Diff line number Diff line change 33const { test } = require ( 'tap' )
44const { MockInterceptor, MockScope } = require ( '../lib/mock/mock-interceptor' )
55const MockAgent = require ( '../lib/mock/mock-agent' ) ;
6+ const { kDispatchKey } = require ( '../lib/mock/mock-symbols' ) ;
67const { InvalidArgumentError } = require ( '../lib/core/errors' )
78
9+
10+ test ( 'MockInterceptor - path' , t => {
11+ t . plan ( 1 )
12+ t . test ( 'should remove hash fragment from paths' , t => {
13+ t . plan ( 1 )
14+ const mockInterceptor = new MockInterceptor ( {
15+ path : '#foobar' ,
16+ method : ''
17+ } , [ ] )
18+ t . equal ( mockInterceptor [ kDispatchKey ] . path , '' )
19+ } )
20+ } )
21+
822test ( 'MockInterceptor - reply' , t => {
923 t . plan ( 2 )
1024
You can’t perform that action at this time.
0 commit comments