fix: ensure correct parser for xml and plaintext (#5597)
Co-authored-by: James George <25279263+jamesgeorge007@users.noreply.github.com>
This commit is contained in:
parent
88c7e189cf
commit
aed032391f
4 changed files with 20 additions and 11 deletions
|
|
@ -1,8 +1,11 @@
|
|||
/* eslint-disable */
|
||||
// @ts-nocheck
|
||||
// biome-ignore lint: disable
|
||||
// oxlint-disable
|
||||
// ------
|
||||
// Generated by unplugin-vue-components
|
||||
// Read more: https://github.com/vuejs/core/pull/3399
|
||||
// biome-ignore lint: disable
|
||||
|
||||
export {}
|
||||
|
||||
/* prettier-ignore */
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@
|
|||
'application/hal+json',
|
||||
'application/vnd.api+json',
|
||||
'application/xml',
|
||||
'text/xml',
|
||||
].includes(body.contentType)
|
||||
"
|
||||
v-tippy="{ theme: 'tooltip' }"
|
||||
|
|
@ -209,7 +210,10 @@ const prettifyRequestBody = () => {
|
|||
try {
|
||||
if (body.value.contentType.endsWith("json")) {
|
||||
prettifyBody = prettifyJSONC(rawParamsBody.value as string)
|
||||
} else if (body.value.contentType === "application/xml") {
|
||||
} else if (
|
||||
body.value.contentType === "application/xml" ||
|
||||
body.value.contentType === "text/xml"
|
||||
) {
|
||||
prettifyBody = prettifyXML(rawParamsBody.value as string)
|
||||
}
|
||||
rawParamsBody.value = prettifyBody
|
||||
|
|
|
|||
|
|
@ -10,22 +10,23 @@ describe("getEditorLangForMimeType", () => {
|
|||
|
||||
test("returns 'xml' for valid XML mimes", () => {
|
||||
expect(getEditorLangForMimeType("application/xml")).toMatch("xml")
|
||||
expect(getEditorLangForMimeType("text/xml")).toMatch("xml")
|
||||
})
|
||||
|
||||
test("returns 'html' for valid HTML mimes", () => {
|
||||
expect(getEditorLangForMimeType("text/html")).toMatch("html")
|
||||
})
|
||||
|
||||
test("returns 'text/x-yaml' for plain text mime", () => {
|
||||
expect(getEditorLangForMimeType("text/plain")).toMatch("text/x-yaml")
|
||||
test("returns text/plain for plain text mime", () => {
|
||||
expect(getEditorLangForMimeType("text/plain")).toBe("text/plain")
|
||||
})
|
||||
|
||||
test("returns 'text/x-yaml' for unimplemented mimes", () => {
|
||||
expect(getEditorLangForMimeType("image/gif")).toMatch("text/x-yaml")
|
||||
test("returns text/plain for unimplemented mimes", () => {
|
||||
expect(getEditorLangForMimeType("image/gif")).toBe("text/plain")
|
||||
})
|
||||
|
||||
test("returns 'text/x-yaml' for null/undefined mimes", () => {
|
||||
expect(getEditorLangForMimeType(null)).toMatch("text/x-yaml")
|
||||
expect(getEditorLangForMimeType(undefined)).toMatch("text/x-yaml")
|
||||
test("returns text/plain for null/undefined mimes", () => {
|
||||
expect(getEditorLangForMimeType(null)).toBe("text/plain")
|
||||
expect(getEditorLangForMimeType(undefined)).toBe("text/plain")
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
const mimeToMode = {
|
||||
"text/plain": "text/x-yaml",
|
||||
"text/plain": "text/plain",
|
||||
"text/xml": "application/xml",
|
||||
"text/html": "htmlmixed",
|
||||
"application/xml": "application/xml",
|
||||
"application/hal+json": "application/ld+json",
|
||||
|
|
@ -8,5 +9,5 @@ const mimeToMode = {
|
|||
}
|
||||
|
||||
export function getEditorLangForMimeType(mimeType: string): string {
|
||||
return mimeToMode[mimeType] || "text/x-yaml"
|
||||
return mimeToMode[mimeType] || "text/plain"
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue