From aed032391f845d7bef55cb0799b9217e87dee243 Mon Sep 17 00:00:00 2001 From: jaeyonglee-int Date: Tue, 2 Dec 2025 06:53:51 -0500 Subject: [PATCH] fix: ensure correct parser for xml and plaintext (#5597) Co-authored-by: James George <25279263+jamesgeorge007@users.noreply.github.com> --- packages/hoppscotch-common/src/components.d.ts | 5 ++++- .../src/components/http/RawBody.vue | 6 +++++- .../src/helpers/__tests__/editorutils.spec.js | 15 ++++++++------- .../hoppscotch-common/src/helpers/editorutils.ts | 5 +++-- 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/packages/hoppscotch-common/src/components.d.ts b/packages/hoppscotch-common/src/components.d.ts index 54bff878..d0329b81 100644 --- a/packages/hoppscotch-common/src/components.d.ts +++ b/packages/hoppscotch-common/src/components.d.ts @@ -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 */ diff --git a/packages/hoppscotch-common/src/components/http/RawBody.vue b/packages/hoppscotch-common/src/components/http/RawBody.vue index 70ff21dd..9cb5179a 100644 --- a/packages/hoppscotch-common/src/components/http/RawBody.vue +++ b/packages/hoppscotch-common/src/components/http/RawBody.vue @@ -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 diff --git a/packages/hoppscotch-common/src/helpers/__tests__/editorutils.spec.js b/packages/hoppscotch-common/src/helpers/__tests__/editorutils.spec.js index 0bd5dac4..f23636f4 100644 --- a/packages/hoppscotch-common/src/helpers/__tests__/editorutils.spec.js +++ b/packages/hoppscotch-common/src/helpers/__tests__/editorutils.spec.js @@ -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") }) }) diff --git a/packages/hoppscotch-common/src/helpers/editorutils.ts b/packages/hoppscotch-common/src/helpers/editorutils.ts index 73302133..72e1e779 100644 --- a/packages/hoppscotch-common/src/helpers/editorutils.ts +++ b/packages/hoppscotch-common/src/helpers/editorutils.ts @@ -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" }