From 94078431c698dfbbb47c9cbd33bcbda5717e7599 Mon Sep 17 00:00:00 2001 From: Edgar Fisher Date: Wed, 23 Feb 2022 15:24:46 +0200 Subject: [PATCH 1/2] [fix] do not decode uri component twice - it may lead to wrongly decoded values if string has '%' symbols --- src/normalize/entries/decodePostDataParams.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/normalize/entries/decodePostDataParams.js b/src/normalize/entries/decodePostDataParams.js index 24ee8ed2..c793dd0b 100644 --- a/src/normalize/entries/decodePostDataParams.js +++ b/src/normalize/entries/decodePostDataParams.js @@ -21,7 +21,10 @@ function getDecodedPostDataParamEntries(entries) { const mimeType = getContentTypeValue(entry.request.postData.mimeType) - if (mimeType !== 'application/x-www-form-urlencoded') { + if ( + mimeType !== 'application/x-www-form-urlencoded' || + entry.request.postData.decoded + ) { return entry } @@ -33,6 +36,7 @@ function getDecodedPostDataParamEntries(entries) { }) entry.request.postData.params = postDataParams + entry.request.postData.decoded = true return entry }) } From a10b5004a7b355a8fbc8e062922b529c44d1ced9 Mon Sep 17 00:00:00 2001 From: Edgar Fisher Date: Wed, 23 Feb 2022 16:26:03 +0200 Subject: [PATCH 2/2] [cr] add tests to make sure postData values are decoded once and update types --- test/unit/normalize/index.test.js | 34 +++++++++++++++++++++++++------ typings/main.d.ts | 1 + 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/test/unit/normalize/index.test.js b/test/unit/normalize/index.test.js index fd7e7967..7bce9319 100644 --- a/test/unit/normalize/index.test.js +++ b/test/unit/normalize/index.test.js @@ -26,18 +26,18 @@ class MockArchive { } } -test('falsy archive', (t) => { +test('falsy archive', t => { // Unmodified archive is returned t.is(normalize(-1), -1) }) -test('falsy archive.log', (t) => { +test('falsy archive.log', t => { const invalid = { test: true } // Unmodified archive is returned t.is(normalize(invalid), invalid) }) -test('falsy archive.log.pages', (t) => { +test('falsy archive.log.pages', t => { const archive = new MockArchive() .addEntry({ id: 'last', @@ -57,13 +57,13 @@ test('falsy archive.log.pages', (t) => { t.notDeepEqual(result, archive) }) -test('falsy archive.log.entries', (t) => { +test('falsy archive.log.entries', t => { const invalid = { log: { pages: [] } } // Unmodified archive is returned t.is(normalize(invalid), invalid) }) -test('entries are sorted', (t) => { +test('entries are sorted', t => { const archive = new MockArchive() .addEntry({ id: 'last', @@ -83,7 +83,7 @@ test('entries are sorted', (t) => { t.is(result.log.entries[2].id, 'last') }) -test('option.addSleep=true', (t) => { +test('option.addSleep=true', t => { const archive = new MockArchive() .addPage({ id: 'page_2' }) .addPage({ id: 'page_1' }) @@ -114,3 +114,25 @@ test('option.addSleep=true', (t) => { t.deepEqual(result.log.entries[2].sleep, [{ [SleepPlacement.After]: 500 }]) // rounded t.deepEqual(result.log.entries[3].sleep, undefined) // last entry has no sleep }) + +test('x-www-form-urlencoded values are decoded once', t => { + const archive = new MockArchive().addEntry({ + request: { + postData: { + mimeType: 'application/x-www-form-urlencoded', + params: [ + { + name: 'name', + value: '80%25', + }, + ], + }, + }, + }).archive + + const normalized = normalize(archive) + const normalizedTwice = normalize(normalized) + + t.is(normalized.log.entries[0].request.postData.params[0].value, '80%') + t.is(normalizedTwice.log.entries[0].request.postData.params[0].value, '80%') +}) diff --git a/typings/main.d.ts b/typings/main.d.ts index 7912443a..5137fc9f 100644 --- a/typings/main.d.ts +++ b/typings/main.d.ts @@ -140,6 +140,7 @@ declare module 'har-to-k6' { export interface PostData extends Body { params: QueryParameter[] comment?: string + decoded?: boolean } export interface URLEncodedParameter {