From 3110225b69e58aac5deb05fc0f9642ec64ddc31f Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Fri, 13 Nov 2020 15:19:05 +0100 Subject: [PATCH] refactor: use exported regex --- src/encoding.ts | 2 +- src/query.ts | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/encoding.ts b/src/encoding.ts index 47964c47..5207d417 100644 --- a/src/encoding.ts +++ b/src/encoding.ts @@ -23,7 +23,7 @@ const AMPERSAND_RE = /&/g // %26 const SLASH_RE = /\//g // %2F const EQUAL_RE = /=/g // %3D const IM_RE = /\?/g // %3F -const PLUS_RE = /\+/g // %2B +export const PLUS_RE = /\+/g // %2B /** * NOTE: It's not clear to me if we should encode the + symbol in queries, it * seems to be less flexible than not doing so and I can't find out the legacy diff --git a/src/query.ts b/src/query.ts index e7903c4b..7d62be27 100644 --- a/src/query.ts +++ b/src/query.ts @@ -1,4 +1,4 @@ -import { decode, encodeQueryKey, encodeQueryValue } from './encoding' +import { decode, encodeQueryKey, encodeQueryValue, PLUS_RE } from './encoding' /** * Possible values in normalized {@link LocationQuery} @@ -51,8 +51,7 @@ export function parseQuery(search: string): LocationQuery { const searchParams = (hasLeadingIM ? search.slice(1) : search).split('&') for (let i = 0; i < searchParams.length; ++i) { // pre decode the + into space - // FIXME: can't import PLUS_RE because it becomes a different regex ??? - const searchParam = searchParams[i].replace(/\+/g, ' ') + const searchParam = searchParams[i].replace(PLUS_RE, ' ') // allow the = character let eqPos = searchParam.indexOf('=') let key = decode(eqPos < 0 ? searchParam : searchParam.slice(0, eqPos)) -- 2.47.3