Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion docker/configurator/translator.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,14 @@ function objectToKeyValueString(env, { injectBaseConfig = false, schema = config
const escapedName = /[^a-zA-Z0-9]/.test(key) ? `"${key}"` : key

if (value.schema.type === "string") {
result += `${escapedName}: "${value.value}",\n`
// The literal string "null" should be emitted as the JS `null` value
// so that env vars like `VALIDATOR_URL=null` correctly disable the
// feature, rather than being treated as the URL "null". See #5519.
if (value.value === "null") {
result += `${escapedName}: null,\n`
} else {
result += `${escapedName}: "${value.value}",\n`
}
} else {
result += `${escapedName}: ${value.value === "" ? `undefined` : value.value},\n`
}
Expand Down
23 changes: 23 additions & 0 deletions test/unit/docker/translator.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,5 +341,28 @@ describe("docker: env translator", function() {
validatorUrl: "http://smartbear.com/",`
).trim())
})

it("should emit `null` (not the string \"null\") for string-typed env vars set to \"null\"", function () {
// Regression test for https://github.com/swagger-api/swagger-ui/issues/5519
// Setting `VALIDATOR_URL=null` in Docker is documented as the way to
// disable the validator badge. Previously this was emitted as the
// string `"null"`, producing a broken link.
const input = {
VALIDATOR_URL: "null"
}

expect(translator(input)).toEqual(`validatorUrl: null,`)
})

it("should emit `null` for other string-typed env vars set to \"null\"", function () {
// The same fix should apply to any string-typed config variable,
// not just VALIDATOR_URL. e.g. URL, FILTER, OAUTH2_REDIRECT_URL.
const input = {
URL: "null",
FILTER: "null"
}

expect(translator(input)).toEqual(`url: null,\nfilter: null,`)
})
})
})