Skip to content

Commit

Permalink
fix: parse boolean values in URL query parameters
Browse files Browse the repository at this point in the history
Refs #9674
  • Loading branch information
glowcloud committed Mar 21, 2024
1 parent 7c4fa83 commit 2f1eb1d
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 11 deletions.
11 changes: 10 additions & 1 deletion src/core/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
44 changes: 34 additions & 10 deletions test/e2e-cypress/e2e/features/syntax-highlighting-json.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand All @@ -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")
})
})
})
5 changes: 5 additions & 0 deletions test/unit/core/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down

0 comments on commit 2f1eb1d

Please sign in to comment.