Repository: louislam/uptime-kuma
File: src/pages/EditMonitor.vue (Vue)

Code before:
            let body = "";
            let basicAuth = "";
            if (this.monitor.method !== "GET") {
                method = ` -X ${this.monitor.method}`;
            }
            if (this.monitor.headers) {
                try {
                    const jsonParsed = JSON.parse(this.monitor.headers);
                    for (const [ key, value ] of Object.entries(jsonParsed)) {
                        headers += ` -H '${key}: ${value}'`;
                    }
                } catch (e) {
                    headers = ` -H '${this.monitor.headers.replace(/\n/g, "")}'`;
                }
            }
            if (this.monitor.body && this.monitor.httpBodyEncoding === "json") {
                let json = "";
                try {
                    const jsonParsed = JSON.parse(this.monitor.body);
                    json = JSON.stringify(jsonParsed);
                    body = ` --json '${json}'`;
                } catch (e) {
                    json = this.monitor.body.replace(/\n/g, "");
                    body = ` --json '${json}'`;
                }
                method = "";
            } else if (this.monitor.body && this.monitor.method === "POST" && this.monitor.httpBodyEncoding === "xml") {
                headers += " -H 'Content-Type: application/xml'";
                body = ` -d ${this.monitor.body.replace(/\n/g, "")}`;
            } else if (this.monitor.body) {
                body = ` -d ${this.monitor.body.replace(/\n/g, "")}`;
            }
            if (this.monitor.authMethod === "basic") {
                basicAuth = ` -u ${this.monitor.basic_auth_user}:${this.monitor.basic_auth_pass}`;
            }
            return `curl -v${method}${this.monitor.timeout ? ` -m ${this.monitor.timeout}` : ""}${this.monitor.ignoreTls ? " -k" : ""}${basicAuth} '${this.monitor.url}'${headers}${body}`;
        },

        ipRegex() {

            // Allow to test with simple dns server with port (127.0.0.1:5300)
            if (! isDev) {
                return this.ipRegexPattern;
            }
            return null;
        },

        pageName() {
            let name = "Add New Monitor";
            if (this.isClone) {
                name = "Clone Monitor";

Review comment (suggestion):
I don't think we reset the method if the `httpBodyEncoding` is `json`, right?

```suggestion
```

Code after:
        DockerHostDialog,
        RemoteBrowserDialog,
        TagsManager,
        VueMultiselect,
        EditMonitorConditions,
    },

    data() {
        return {
            modal: null,
            minInterval: MIN_INTERVAL_SECOND,
            maxInterval: MAX_INTERVAL_SECOND,
            processing: false,
            monitor: {
                notificationIDList: {},
                // Do not add default value here, please check init() method
            },
            acceptedStatusCodeOptions: [],
            dnsresolvetypeOptions: [],
            kafkaSaslMechanismOptions: [],
            ipOrHostnameRegexPattern: hostNameRegexPattern(),
            mqttIpOrHostnameRegexPattern: hostNameRegexPattern(true),
            gameList: null,
            connectionStringTemplates: {
                "sqlserver": "Server=<hostname>,<port>;Database=<your database>;User Id=<your user id>;Password=<your password>;Encrypt=<true/false>;TrustServerCertificate=<Yes/No>;Connection Timeout=<int>",
                "postgres": "postgres://username:password@host:port/database",
                "mysql": "mysql://username:password@host:port/database",
                "redis": "redis://user:password@host:port",
                "mongodb": "mongodb://username:password@host:port/database",
            },
            draftGroupName: null,
            remoteBrowsersEnabled: false,
        };
    },

    computed: {

        curlCommand() {
            const command = [ "curl", "--verbose", "--head", "--request", this.monitor.method, "\\\n", "--user-agent", userAgent, "\\\n" ];
            if (this.monitor.ignoreTls) {
                command.push("--insecure", "\\\n");
            }
            if (this.monitor.headers) {
                try {
                    // trying to parse the supplied data as json to trim whitespace
                    for (const [ key, value ] of Object.entries(JSON.parse(this.monitor.headers))) {
                        command.push("--header", `'${key}: ${value}'`, "\\\n");
                    }
                } catch (e) {
                    command.push("--header", `'${this.monitor.headers}'`, "\\\n");
                }