Skip to content

Ignoring trailing slash in MockAgent.prototype.get #4342

@lisez

Description

@lisez

This would solve...

I encountered an issue when changing the target URL, specifically due to a difference in the trailing slash.

For example:

  • http://example.com vs. http://example.com/

After reviewing the implementation in MockAgent, I realized the root cause:

get (origin) {
let dispatcher = this[kMockAgentGet](origin)
if (!dispatcher) {
dispatcher = this[kFactory](origin)
this[kMockAgentSet](origin, dispatcher)
}
return dispatcher
}

It uses the full URL string as a key in a map.

Therefore, the presence or absence of the trailing slash significantly affects the lookup behavior.

The implementation should look like...

To address this, it might be possible to leverage the ignoreTrailingSlash option provided by MockAgent.

The implementation could look like this:

 get (origin) { 
   const key = this[kIgnoreTrailingSlash]? origin.replace(/\/$/, '') : origin;
   let dispatcher = this[kMockAgentGet](key) 
  
   if (!dispatcher) { 
     dispatcher = this[kFactory](key) 
     this[kMockAgentSet](key, dispatcher) 
   } 
   return dispatcher 
 } 

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions