Skip to content

Commit aed0323

Browse files
fix: ensure correct parser for xml and plaintext (hoppscotch#5597)
Co-authored-by: James George <[email protected]>
1 parent 88c7e18 commit aed0323

File tree

4 files changed

+20
-11
lines changed

4 files changed

+20
-11
lines changed

packages/hoppscotch-common/src/components.d.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
/* eslint-disable */
22
// @ts-nocheck
3+
// biome-ignore lint: disable
4+
// oxlint-disable
5+
// ------
36
// Generated by unplugin-vue-components
47
// Read more: https://github.com/vuejs/core/pull/3399
5-
// biome-ignore lint: disable
8+
69
export {}
710

811
/* prettier-ignore */

packages/hoppscotch-common/src/components/http/RawBody.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
'application/hal+json',
3636
'application/vnd.api+json',
3737
'application/xml',
38+
'text/xml',
3839
].includes(body.contentType)
3940
"
4041
v-tippy="{ theme: 'tooltip' }"
@@ -209,7 +210,10 @@ const prettifyRequestBody = () => {
209210
try {
210211
if (body.value.contentType.endsWith("json")) {
211212
prettifyBody = prettifyJSONC(rawParamsBody.value as string)
212-
} else if (body.value.contentType === "application/xml") {
213+
} else if (
214+
body.value.contentType === "application/xml" ||
215+
body.value.contentType === "text/xml"
216+
) {
213217
prettifyBody = prettifyXML(rawParamsBody.value as string)
214218
}
215219
rawParamsBody.value = prettifyBody

packages/hoppscotch-common/src/helpers/__tests__/editorutils.spec.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,23 @@ describe("getEditorLangForMimeType", () => {
1010

1111
test("returns 'xml' for valid XML mimes", () => {
1212
expect(getEditorLangForMimeType("application/xml")).toMatch("xml")
13+
expect(getEditorLangForMimeType("text/xml")).toMatch("xml")
1314
})
1415

1516
test("returns 'html' for valid HTML mimes", () => {
1617
expect(getEditorLangForMimeType("text/html")).toMatch("html")
1718
})
1819

19-
test("returns 'text/x-yaml' for plain text mime", () => {
20-
expect(getEditorLangForMimeType("text/plain")).toMatch("text/x-yaml")
20+
test("returns text/plain for plain text mime", () => {
21+
expect(getEditorLangForMimeType("text/plain")).toBe("text/plain")
2122
})
2223

23-
test("returns 'text/x-yaml' for unimplemented mimes", () => {
24-
expect(getEditorLangForMimeType("image/gif")).toMatch("text/x-yaml")
24+
test("returns text/plain for unimplemented mimes", () => {
25+
expect(getEditorLangForMimeType("image/gif")).toBe("text/plain")
2526
})
2627

27-
test("returns 'text/x-yaml' for null/undefined mimes", () => {
28-
expect(getEditorLangForMimeType(null)).toMatch("text/x-yaml")
29-
expect(getEditorLangForMimeType(undefined)).toMatch("text/x-yaml")
28+
test("returns text/plain for null/undefined mimes", () => {
29+
expect(getEditorLangForMimeType(null)).toBe("text/plain")
30+
expect(getEditorLangForMimeType(undefined)).toBe("text/plain")
3031
})
3132
})
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const mimeToMode = {
2-
"text/plain": "text/x-yaml",
2+
"text/plain": "text/plain",
3+
"text/xml": "application/xml",
34
"text/html": "htmlmixed",
45
"application/xml": "application/xml",
56
"application/hal+json": "application/ld+json",
@@ -8,5 +9,5 @@ const mimeToMode = {
89
}
910

1011
export function getEditorLangForMimeType(mimeType: string): string {
11-
return mimeToMode[mimeType] || "text/x-yaml"
12+
return mimeToMode[mimeType] || "text/plain"
1213
}

0 commit comments

Comments
 (0)