Is there a way to fetch a URL that ends with a dot-segment?

294 Views Asked by At

My goal is to fetch a URL that ends with a dot-segment, so a URL that ends with a literal dot/period: .

Example:

I expected the following invocation of fetch to result in an HTTP GET request on the base URI of the site with the path /api/users/. (notice the literal dot at the end)

await fetch("/api/users/.")

Instead, it results in the path <base URI>/api/users/ to be requested (notice the missing dot)

This section of RFC 3986 describes the behaviour to remove dot-segments: https://datatracker.ietf.org/doc/html/rfc3986#section-5.2.4

Now, I tried to URI-escape the dot with %2e, giving me the following request path: /api/users/%2e

Unfortunately, the same behaviour occurs, tested on Firefox and on Chrome.

I am baffled how to achieve this in a Browser-based environment using the Browser's fetch API.

I know that using cURL this is as easy as specifying an additional parameter (otherwise the same behaviour occurs also using cURL):

curl --path-as-is "http://localhost:8080/api/users/."

However, I have not found any such config possibility for fetch.

1

There are 1 best solutions below

0
ckunz On

The workaround to encode the dot-segment with %2e does solve the problem.

Source of confusion was: A server may decide to redirect <url>/. to <url>, so maybe check the network panel for a 302 Found where a different link is provided as header.

I didn't notice this behaviour at first and together with a few other issues I was confused and thought the workaround didn't work.