From: Eduardo San Martin Morote Date: Tue, 4 Feb 2020 18:05:08 +0000 (+0100) Subject: fix: encode query X-Git-Tag: v4.0.0-alpha.0~48 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3a55bf73407380d72bb342ce282b82a492c20c65;p=thirdparty%2Fvuejs%2Frouter.git fix: encode query --- diff --git a/src/history/common.ts b/src/history/common.ts index aca47ce9..c1492ff7 100644 --- a/src/history/common.ts +++ b/src/history/common.ts @@ -1,4 +1,5 @@ import { ListenerRemover } from '../types' +import { decode, encodeQueryProperty } from '../utils/encoding' // import { encodeQueryProperty, encodeHash } from '../utils/encoding' export type HistoryQuery = Record @@ -163,6 +164,8 @@ export function parseQuery(search: string): HistoryQuery { const searchParams = (hasLeadingIM ? search.slice(1) : search).split('&') for (let i = 0; i < searchParams.length; ++i) { let [key, value] = searchParams[i].split('=') + key = decode(key) + value = decode(value) if (key in query) { // an extra variable for ts types let currentValue = query[key] @@ -182,9 +185,10 @@ export function parseQuery(search: string): HistoryQuery { */ export function stringifyQuery(query: HistoryQuery): string { let search = '' - for (const key in query) { + for (let key in query) { if (search.length > 1) search += '&' const value = query[key] + key = encodeQueryProperty(key) if (value === null) { // TODO: should we just add the empty string value? search += key @@ -194,9 +198,9 @@ export function stringifyQuery(query: HistoryQuery): string { let values: string[] = Array.isArray(value) ? value : [value] // const encodedValues = values.map(encodeQueryProperty) - search += `${key}=${values[0]}` + search += `${key}=${encodeQueryProperty(values[0])}` for (let i = 1; i < values.length; i++) { - search += `&${key}=${values[i]}` + search += `&${key}=${encodeQueryProperty(values[i])}` } }