From a73a787753a24259ec0846ea5e9c92d072e1fe89 Mon Sep 17 00:00:00 2001 From: MeiMei <30769358+mei23@users.noreply.github.com> Date: Fri, 1 Oct 2021 02:25:57 +0900 Subject: [PATCH] Fix prelude/url (#7855) --- src/prelude/url.ts | 2 +- test/prelude/url.ts | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 test/prelude/url.ts diff --git a/src/prelude/url.ts b/src/prelude/url.ts index ce75fe89d..c7f2b7c1e 100644 --- a/src/prelude/url.ts +++ b/src/prelude/url.ts @@ -4,7 +4,7 @@ export function query(obj: {}): string { .reduce((a, [k, v]) => (a[k] = v, a), {} as Record); return Object.entries(params) - .map((e) => `${e[0]}=${e[1]}`) + .map((e) => `${e[0]}=${encodeURIComponent(e[1])}`) .join('&'); } diff --git a/test/prelude/url.ts b/test/prelude/url.ts new file mode 100644 index 000000000..1f814968a --- /dev/null +++ b/test/prelude/url.ts @@ -0,0 +1,13 @@ +import * as assert from 'assert'; +import { query } from '../../src/prelude/url'; + +describe('url', () => { + it('query', () => { + const s = query({ + foo: 'ふぅ', + bar: 'b a r', + baz: undefined + }); + assert.deepStrictEqual(s, 'foo=%E3%81%B5%E3%81%85&bar=b%20a%20r'); + }); +});