Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

ngMock: wrong parsing of pathParams when there are queryParams #14173

Closed
marcoancona opened this issue Mar 3, 2016 · 2 comments
Closed

ngMock: wrong parsing of pathParams when there are queryParams #14173

marcoancona opened this issue Mar 3, 2016 · 2 comments

Comments

@marcoancona
Copy link

  • Do you want to request a feature or report a bug?
    This is a bug.

  • What is the current behavior?
    httpBackend.whenRoute() does not parse correctly the path-parameters when they are immediately followed by query-parameters.

    Consider the following example:
    $httpBackend.whenRoute('DELETE', '/api/resource/:_id').respond((method, url, data, header, params) => {}

    If whenRoute is triggered by /api/resource/1?q=hello, params will contain wrong parsing of the id:

    params = {id: '1?q=hello', 'q': 'hello'}

  • What is the expected behavior?
    params = {id: '1', q: 'hello'}

  • What is the motivation / use case for changing the behavior?
    This behaviour looks wrong and inconsistent.

  • Which version of Angular, and which browser and OS does this issue affect? Did this work in previous
    versions of Angular? Please also test with the latest stable and snapshot versions.
    Angular 1.5, in previous releases params was not generated

  • Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix)

@gkalpak
Copy link
Member

gkalpak commented Mar 5, 2016

A little background:

(Almost) the same logic is used in ngMock's parseRoute() and ngResource's pathRegExp().
(It should be the same logic, but they seem to have gotten slightly out of sync.)

The one intentional difference is this:

In ngResource we match the RegExp against $location.path() (not the whole URL, containing the query). Thus we don't have to take special care to avoid matching the query.
In ngMock, we need to have a way to ignore the query/hash part for whenRoute().

@ferrao
Copy link

ferrao commented Oct 27, 2016

👍

@Narretz Narretz modified the milestones: 1.5.x, 1.7.x Apr 12, 2018
@petebacondarwin petebacondarwin self-assigned this May 14, 2018
thorn0 added a commit to thorn0/angular.js that referenced this issue Jun 3, 2018
thorn0 added a commit to thorn0/angular.js that referenced this issue Jun 4, 2018
thorn0 added a commit to thorn0/angular.js that referenced this issue Jun 4, 2018
thorn0 added a commit to thorn0/angular.js that referenced this issue Jun 4, 2018
thorn0 added a commit to thorn0/angular.js that referenced this issue Jun 5, 2018
thorn0 added a commit to thorn0/angular.js that referenced this issue Jun 5, 2018
thorn0 added a commit to thorn0/angular.js that referenced this issue Jun 5, 2018
thorn0 added a commit to thorn0/angular.js that referenced this issue Jun 5, 2018
thorn0 added a commit to thorn0/angular.js that referenced this issue Jun 5, 2018
thorn0 added a commit to thorn0/angular.js that referenced this issue Jun 5, 2018
thorn0 added a commit to thorn0/angular.js that referenced this issue Jun 6, 2018
thorn0 added a commit to thorn0/angular.js that referenced this issue Jun 8, 2018
thorn0 added a commit to thorn0/angular.js that referenced this issue Jun 9, 2018
thorn0 added a commit to thorn0/angular.js that referenced this issue Jun 9, 2018
thorn0 added a commit to thorn0/angular.js that referenced this issue Jun 9, 2018
thorn0 added a commit to thorn0/angular.js that referenced this issue Jun 10, 2018
gkalpak pushed a commit that referenced this issue Jun 18, 2018
…en}Route

Previously, a route definition such as
`$httpBackend.whenRoute('GET', '/route/:id')` matched against a URL with
query params, for example `/route/1?q=foo`, would incorrectly include
the query params in `id`: `{id: '1?q=foo', q: 'foo'}`.

This commit fixes it, so that the extracted `params` will now be:
`{id: '1', q: 'foo'}`.

Fixes #14173

Closes #16589
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants