From 2f1eb1d56a69f25743e31926390fdd018598bd26 Mon Sep 17 00:00:00 2001 From: Oliwia Rogala Date: Thu, 21 Mar 2024 10:51:15 +0100 Subject: [PATCH] fix: parse boolean values in URL query parameters Refs #9674 --- src/core/utils/index.js | 11 ++++- .../features/syntax-highlighting-json.cy.js | 44 ++++++++++++++----- test/unit/core/utils.js | 5 +++ 3 files changed, 49 insertions(+), 11 deletions(-) diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 9ff5770ee2e..e27b74f682a 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -619,7 +619,16 @@ export const parseSearch = () => { continue } i = params[i].split("=") - map[decodeURIComponent(i[0])] = (i[1] && decodeURIComponent(i[1])) || "" + + let value = i[1] ? decodeURIComponent(i[1]) : "" + + if (value === "true") { + value = true + } else if (value === "false") { + value = false + } + + map[decodeURIComponent(i[0])] = value } } diff --git a/test/e2e-cypress/e2e/features/syntax-highlighting-json.cy.js b/test/e2e-cypress/e2e/features/syntax-highlighting-json.cy.js index 236aabaa761..be1dbd473ec 100644 --- a/test/e2e-cypress/e2e/features/syntax-highlighting-json.cy.js +++ b/test/e2e-cypress/e2e/features/syntax-highlighting-json.cy.js @@ -8,17 +8,29 @@ describe("Syntax Highlighting for JSON value cases", () => { describe("OAS 2", () => { it("should render full syntax highlighted string in Request (param body) example", () => { cy.visit("/?url=/documents/features/syntax-highlighting-json-oas2.yaml") - .get("#operations-default-post_setServices") - .click() - .get(".body-param__example > .language-json > :nth-child(10)") - .should("have.text", "\"79daf5b4-aa4b-1452-eae5-42c231477ba7\"") + .get("#operations-default-post_setServices") + .click() + .get(".body-param__example > .language-json > :nth-child(10)") + .should("have.text", '"79daf5b4-aa4b-1452-eae5-42c231477ba7"') }) it("should render full syntax highlighted string in Response example", () => { cy.visit("/?url=/documents/features/syntax-highlighting-json-oas2.yaml") - .get("#operations-default-post_setServices") - .click() - .get(".example > .language-json > :nth-child(28)") - .should("have.text", "\"5ff06f632bb165394501b05d3a833355\"") + .get("#operations-default-post_setServices") + .click() + .get(".example > .language-json > :nth-child(28)") + .should("have.text", '"5ff06f632bb165394501b05d3a833355"') + }) + it("should not render syntax highlighted string when syntaxHighlight.activated is set to false", () => { + cy.visit( + "/?syntaxHighlight.activated=false&url=/documents/features/syntax-highlighting-json-oas2.yaml" + ) + .get("#operations-default-post_setServices") + .click() + .get(".example > .language-json") + .should("not.exist") + .get(".example") + .contains('"5ff06f632bb165394501b05d3a833355"') + .should("exist") }) }) describe("OAS 3", () => { @@ -27,14 +39,26 @@ describe("Syntax Highlighting for JSON value cases", () => { .get("#operations-default-post_setServices") .click() .get(".body-param__example > .language-json > :nth-child(15)") - .should("have.text", "\"22a124b4-594b-4452-bdf5-fc3ef1477ba7\"") + .should("have.text", '"22a124b4-594b-4452-bdf5-fc3ef1477ba7"') }) it("should render full syntax highlighted string in Response example", () => { cy.visit("/?url=/documents/features/syntax-highlighting-json-oas3.yaml") .get("#operations-default-post_setServices") .click() .get(".example > .language-json > :nth-child(33)") - .should("have.text", "\"f0009babde9dbe204540d79cf754408e\"") + .should("have.text", '"f0009babde9dbe204540d79cf754408e"') + }) + it("should not render syntax highlighted string when syntaxHighlight is set to false", () => { + cy.visit( + "/?syntaxHighlight=false&url=/documents/features/syntax-highlighting-json-oas3.yaml" + ) + .get("#operations-default-post_setServices") + .click() + .get(".example > .language-json") + .should("not.exist") + .get(".example") + .contains('"f0009babde9dbe204540d79cf754408e"') + .should("exist") }) }) }) diff --git a/test/unit/core/utils.js b/test/unit/core/utils.js index a733543e63e..e69b33a1e88 100644 --- a/test/unit/core/utils.js +++ b/test/unit/core/utils.js @@ -1326,6 +1326,11 @@ describe("utils", () => { win.location.search = "?foo=foo%20bar" expect(parseSearch()).toEqual({foo: "foo bar"}) }) + + it("parses boolean values", () => { + win.location.search = "?foo=true&bar=false" + expect(parseSearch()).toEqual({foo: true, bar: false}) + }) }) describe("serializing", () => {