angular / in-memory-web-api

The code for this project has moved to the angular/angular repo. This repo is now archived.
MIT License
1.18k stars 231 forks source link

parseUrl cannot handle URI's contain the `@` symbbol #232

Open markewallace opened 5 years ago

markewallace commented 5 years ago

I've run into an issue where I need to change my applications behaviour so that it works with both the in memory service and the real API.

Here is the scenario:

  1. We have a API that supports searching for users by email so we could call it something like this http://localhost:4200/api/search?query=foo@bar.com
  2. When running with the in memory service I have to encode the query parameter
  3. But if I do that when running with the real API I end up with the query parameter value being doubly encode

The problem seems to be in the parseUri method.

Here's a single example I created to reproduce the issue: https://stackblitz.com/edit/angular-nckow7

This is how the URI get's parsed

{
    "source": "http://localhost:4200/api/search?query=foo@bar.com",
    "protocol": "http",
    "authority": "localhost:4200/api/search?query=foo@bar.com",
    "userInfo": "localhost:4200/api/search?query=foo",
    "user": "localhost",
    "password": "4200/api/search?query=foo",
    "host": "bar.com",
    "port": "",
    "relative": "",
    "path": "",
    "directory": "",
    "file": "",
    "query": "",
    "anchor": ""
}

According to the RFC 3986 the @ symbol is valid, see: https://stackoverflow.com/questions/1547899/which-characters-make-a-url-invalid/1547940#1547940

Is this a valid defect?

ctaleck commented 5 years ago

It is valid because it designates the start of the "password" param. Try encoding the @ as %40 if you want to use it in the "query" param.