ladjs / superagent

Ajax for Node.js and browsers (JS HTTP client). Maintained for @forwardemail, @ladjs, @spamscanner, @breejs, @cabinjs, and @lassjs.
https://ladjs.github.io/superagent/
MIT License
16.59k stars 1.33k forks source link

Smileys and Emojis are not sent in correct format in POST request #1570

Open brendamckenne opened 4 years ago

brendamckenne commented 4 years ago

Hi I have a simple text field in which I allow text or emojis/smileys to be added and then when the user clicks "Send" button, I send the request via SuperAgent to my backend controller. When I debug my backend controller values, the values I see are garbage values and not the ones that are coming from the UI.

This happens only with Smileys and Emoji characters. The plain text appears correct.

Note that this issue persist only when using superagent. When I use the $.post() approach of sending ajax request, I get the data in correct format in my backend.

Example code which is NOT working:


request.set('Content-Type', 'application/x-www-form-urlencoded')
                .set('deviceType', 'browser')
                .send({ userId: userId })
                .send({ text: text })  // THIS TEXT CONTAINS PLAIN TEXT AND SMILEYS/EMOJIS
                .then(res => {
                    if (res.statusCode == 200) {
                        if (actionType == "reply") {
                            alert("Reply added successfully","info",true);
                        } else if (actionType == "reply-edit") {
                            alert("Reply added successfully","info",true);
                        } else {
                            alert("Comment added successfully","info",true);
                        }
                    } else {
                        alert("An unexpected error occured while processing your request. Please try again later.", "error",false);
                    }
                }).catch(err => {
                console.log("Error: "+err);
                alert("An unexpected error occured while processing your request. Please try again later.", "error",false);
            });