etherpad-lite icon indicating copy to clipboard operation
etherpad-lite copied to clipboard

eth.setHTML(padId, html) accent issue

Open javierpf opened this issue 9 years ago • 13 comments

When a new pad is created and then use the setHTML method to include some text with accents (e.g. ción ción) shows like this image When i edit the same pad, accents are accepted and saved correctly image

javierpf avatar May 05 '17 15:05 javierpf

What database are you using? Looks like encoding issues. AFAIK using a browser seems to be okay, because internally all db-interaction is cached. When you are typing you see what you type. On reload you will be served data from the db cache if it is still there.

To be really sure the cache is cleared you need to restart the server. If I am correct, the first line in your second image should be wrong after that.

webzwo0i avatar May 05 '17 16:05 webzwo0i

After the refresh i can check that the first line in the second image has accents. The database stores it correctly. I'm thinking about the encoding of the request from the backend when i create the pad. There's a header in the API to set it as a parameter or something?

javierpf avatar May 08 '17 15:05 javierpf

We are still having this issue @webzwo0i Do you have any news on this?

cdparra avatar May 25 '17 03:05 cdparra

Any news regarding this issue?

cdparra avatar Jun 22 '17 15:06 cdparra

We have experienced the same problem on our side aswell. It is not only for setHTML. It is also for setting the default text in the createGroupPad method aswell. We are using the Java API to connect with the node.js server. Can someone of the developer try to create a pad with one of those characters over the api and explain why this encoding issue happens? ö, ä, ü, ß

renebrain avatar Jun 28 '17 09:06 renebrain

The problem is that the HTML need to be sent encoded to the API. The Ruby API does that (I'm not getting the same issues you are, so I was puzzled about that and started investigating), maybe the Java one does not.

Using curl without encoding:

curl "http://my.instance.com/api/1.2.13/setHTML?apikey=secret&padID=test&html=<html><head></head><body>ß</body></html>"

Result: image

Now curl + encoding:

curl "http://my.instance.com/api/1.2.13/setHTML?apikey=secret&padID=test&html=<html><head></head><body>%C3%9F</body></html>"

Result: image

Hope this helps.

lpagliari avatar Jul 01 '17 11:07 lpagliari

Can anyone tell me what do you guys mean by encoding plain text before saving it in Java? Thanks.

kernelfreak avatar Jul 03 '17 09:07 kernelfreak

@kernelfreak you don't need to save anything, you just need to transform the text you are sending to the Etherpad client.

This should actually be handled on the Java client (more precisely here), but if you don't want to wait for them to fix it, you can handle the text encoding yourself:

import java.net.URLEncoder;
(...)
EPLiteClient client = new EPLiteClient("http://localhost:9001", "K8OF91QMQYUvrNu3e9rJ7FnnVgaB3m9q");
String originalText = "ö, ä, ü, ß";
String encodedText = URLEncoder.encode(originalText, "UTF-8");
client.setText("my_pad", encodedText);

lpagliari avatar Jul 03 '17 13:07 lpagliari

@javierpf @cdparra are you using the Java client too?

lpagliari avatar Jul 03 '17 13:07 lpagliari

@lpagliari yes, we are using the Java client. I will try your solution Today and see if it works (I can trie to do it directly in the client code and then submit a pull request)

cdparra avatar Jul 03 '17 13:07 cdparra

I can trie to do it directly in the client code and then submit a pull request

Perfect! That would be even better. Thanks!

lpagliari avatar Jul 03 '17 13:07 lpagliari

Just tried this out and it works. I created a pull request for the java-etherpad-client I am using (not sure if there is another one)

cdparra avatar Jul 05 '17 20:07 cdparra

I encoded the text with URLEncoder.encode("text","UTF-8") and then it worked. Thank you.

kernelfreak avatar Jul 19 '17 09:07 kernelfreak