Skip to content

Commit 55d3e4d

Browse files
author
Anatoly Ostrovsky
committed
Test fixes
1 parent cf4833c commit 55d3e4d

4 files changed

Lines changed: 16 additions & 19 deletions

File tree

@types/shared/utils.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,10 +427,10 @@ export function fromJson(json: string): any | Array<any> | string | number;
427427
export function addDateMinutes(date: Date, minutes: number): Date;
428428
/**
429429
* Parses an escaped url query string into key-value pairs.
430-
* @param {string} keyValue
430+
* @param {string} value
431431
* @returns {Object.<string,boolean|Array<any>>}
432432
*/
433-
export function parseKeyValue(keyValue: string): {
433+
export function parseKeyValue(value: string): {
434434
[x: string]: boolean | any[];
435435
};
436436
/**

src/services/location/location.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,11 @@ export class Location {
102102
throw $locationMinErr("badurl", 'Invalid url "{0}".', url);
103103
}
104104

105-
if (match[1] !== undefined || url === "") {
105+
if (match[1] || url === "") {
106106
this.setPath(match[1] || "");
107107
}
108108

109-
if (match[2] !== undefined || match[1] !== undefined || url === "") {
109+
if (match[2] || match[1] || url === "") {
110110
this.setSearch(match[3] || "");
111111
}
112112

@@ -134,10 +134,7 @@ export class Location {
134134
validateRequired(path, "path");
135135
let newPath = path !== null ? path.toString() : "";
136136

137-
if (this.html5) {
138-
// decode reserved characters except slashes
139-
newPath = decodePath(newPath, false);
140-
}
137+
newPath = decodePath(newPath, this.html5);
141138

142139
_path = newPath.charAt(0) === "/" ? newPath : `/${newPath}`;
143140
this._compose();

src/services/location/location.spec.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ describe("$location", () => {
9494
"http://www.domain.com:9877/",
9595
true,
9696
);
97-
debugger;
9897
locationUrl.parse(
9998
"http://www.domain.com:9877/path/b?search=a&b=c&d#hash",
10099
);
@@ -285,7 +284,6 @@ describe("$location", () => {
285284
it("url getter/setter should change only hash when no search and path specified", () => {
286285
const locationUrl = createLocationHtml5Url();
287286
expect(locationUrl.getUrl()).toBe("/path/b?search=a&b=c&d#hash");
288-
289287
locationUrl.setUrl("#some-hash");
290288

291289
expect(locationUrl.getHash()).toBe("some-hash");
@@ -435,7 +433,7 @@ describe("$location", () => {
435433

436434
it("should allow to set both URL and state", () => {
437435
const locationUrl = createLocationHtml5Url();
438-
locationUrl.setUrl("/foo");
436+
locationUrl.setUrl("/foo").setState({ a: 2 });
439437
expect(locationUrl.getUrl()).toEqual("/foo");
440438
expect(locationUrl.getState()).toEqual({ a: 2 });
441439
});

src/shared/utils.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -786,27 +786,29 @@ export function addDateMinutes(date, minutes) {
786786

787787
/**
788788
* Parses an escaped url query string into key-value pairs.
789-
* @param {string} keyValue
789+
* @param {string} value
790790
* @returns {Object.<string,boolean|Array<any>>}
791791
*/
792-
export function parseKeyValue(keyValue) {
792+
export function parseKeyValue(value) {
793793
/** @type {Record<string, boolean | string | Array<any>>} */
794794
const obj = {};
795795

796-
(keyValue || "").split("&").forEach((item) => {
796+
const res = value || "";
797+
798+
res.split("&").forEach((keyValue) => {
797799
let splitPoint;
798800

799801
let key;
800802

801803
let val;
802804

803-
if (item) {
804-
key = keyValue = item.replace(/\+/g, "%20");
805-
splitPoint = item.indexOf("=");
805+
if (keyValue) {
806+
key = keyValue = keyValue.replace(/\+/g, "%20");
807+
splitPoint = keyValue.indexOf("=");
806808

807809
if (splitPoint !== -1) {
808-
key = item.substring(0, splitPoint);
809-
val = item.substring(splitPoint + 1);
810+
key = keyValue.substring(0, splitPoint);
811+
val = keyValue.substring(splitPoint + 1);
810812
}
811813
key = tryDecodeURIComponent(key);
812814

0 commit comments

Comments
 (0)