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

Commit 132344c

Browse files
committed
refactor(ngMocks): ignore query/hash when extracting path params for MockHttpExpectation
1 parent 321ee99 commit 132344c

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/ngMock/angular-mocks.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -2092,6 +2092,9 @@ function assertArgDefined(args, index, name) {
20922092
}
20932093
}
20942094

2095+
function stripQueryAndHash(url) {
2096+
return url.replace(/[?#].*$/, '');
2097+
}
20952098

20962099
function MockHttpExpectation(method, url, data, headers, keys) {
20972100

@@ -2146,15 +2149,17 @@ function MockHttpExpectation(method, url, data, headers, keys) {
21462149

21472150
this.params = function(u) {
21482151
var queryStr = u.indexOf('?') === -1 ? '' : u.substring(u.indexOf('?') + 1);
2152+
var strippedUrl = stripQueryAndHash(u);
21492153

2150-
return angular.extend(parseQuery(queryStr), pathParams());
2154+
return angular.extend(parseQuery(queryStr), pathParams(strippedUrl));
21512155

2152-
function pathParams() {
2156+
function pathParams(strippedUrl) {
21532157
var keyObj = {};
21542158
if (!url || !angular.isFunction(url.test) || !keys || keys.length === 0) return keyObj;
21552159

2156-
var m = url.exec(u);
2160+
var m = url.exec(strippedUrl);
21572161
if (!m) return keyObj;
2162+
21582163
for (var i = 1, len = m.length; i < len; ++i) {
21592164
var key = keys[i - 1];
21602165
var val = m[i];

0 commit comments

Comments
 (0)