lundi 10 juin 2019

How to prevent the carriage return character that appends in a html form textarea?

I just encountered a bug in my rails3 application while setting up WhatsApp messaging service via a third party API.

I have my message template set at the 3rd party portal. Now when my client is hitting the API with the message content, I encounter the response : "error | 318 | Message does not match WhatsApp HSM template."

After thorough debugging I realised the message content (which is an input from admin on my application) appends a "\r" character before every "\n" character when the content is submitted via html form.

However the content at the 3rd party has only "\n" character leading to the mismatch.

I need help with how I can avoid "\r" append.

I read the cause could be a copy paste from different encoding sources, like MS Word. I tried to test this theory with (Ubuntu) LibreOffice Writer and Text Editor, and it was of no use.

However if I update the content with rails console, I get the desired result (no "\r" append)

This is how my data looks in 2 scenarios:

Through input in an html form: (actual) Some text \r\n\r\nFor more details, check out this.

Through rails console: (desired) Some text \n\nFor more details, check out this.

Aucun commentaire:

Enregistrer un commentaire