Skip to content

Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia

fix(raw-params): syntax fix, set default only when params is empty or old default

Leonardo Matosf2c3bd54d66f
diff --git a/pages/index.vue b/pages/index.vue
index e2f823396..e59cc6b65 100644
--- a/pages/index.vue
+++ b/pages/index.vue
@@ -1435,23 +1435,21 @@ export default {
canListParameters(canToggleRaw) {
this.rawInput = !canToggleRaw
},
- contentType(contentType) {
- switch (contentType) {
- case "application/json":
- case "application/hal+json":
- if (!(this.rawParams.charAt(0) in ['"', "{", "["])) {
- this.rawParams = "{}"
- }
- break
- case "application/xml":
- if (this.rawParams.charAt(0) !== "<" || this.rawParams === "<!doctype html>") {
- this.rawParams = "<?xml version='1.0' encoding='utf-8'?>"
- }
- break
- case "text/html":
- if (this.rawParams.charAt(0) !== "<" || this.rawParams.startsWith("<?xml")) {
- this.rawParams = "<!doctype html>"
- }
+ contentType(contentType, oldContentType) {
+ const getDefaultParams = contentType => {
+ switch (contentType) {
+ case "application/json":
+ case "application/hal+json":
+ return "{}"
+ case "application/xml":
+ return "<?xml version='1.0' encoding='utf-8'?>"
+ case "text/html":
+ return "<!doctype html>"
+ }
+ return ""
+ }
+ if (!this.rawParams || this.rawParams === getDefaultParams(oldContentType)) {
+ this.rawParams = getDefaultParams(contentType)
}
this.setRouteQueryState()
},