0

I'm saving data to firebase RTDB through JS SDK (6.3.1) using:

 firebase.initializeApp(firebaseConfig);
  var data={
      "name":"Česká republika"
  };
  var key = firebase.database().ref().child('areas').push(data).key;

There's a problem with special characters, when I view them in Firebase console. It's scary, but firebase SOMETIMES gets the characters right and sometimes doesn't. The following output was achieved only by refreshing the script (The script file is encoded in UTF-8):

firebase-output

Also sending characters in a form like \u00e9 doesn't help. They too are received sometimes nicely, sometimes not. Thanks for your ideas!

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Fanky
  • 1,673
  • 1
  • 18
  • 20
  • 1
    Are you sure, that your local file is in the right encoding? Try converting it via Notepad++, IntelliJ or any other IDE/Editor, that can convert file encoding. – MauriceNino Jul 24 '19 at 09:06
  • The file is in UTF-8 without BOM, converted and set up by Notepad++. Same behavior when I convert it to UTF-8 with BOM and set the format to it. – Fanky Jul 24 '19 at 09:09
  • Have you tried using a different framework? – MauriceNino Jul 24 '19 at 09:13
  • What do you mean by framework? I use JS SDK scripts (https://www.gstatic.com/firebasejs/6.3.0/firebase-app.js etc.) provided by firebase for webapps. Just in a test file. – Fanky Jul 24 '19 at 09:14
  • Tested now with 6.3.1, same results – Fanky Jul 24 '19 at 09:21
  • Yeah, but AFAIK there are other Firebase frameworks. Maybe one of them offer options to encode data correctly. Or you can try out this answer, maybe it helps: https://stackoverflow.com/a/19148116/9150652 – MauriceNino Jul 24 '19 at 10:19
  • I can't reproduce the problem: https://jsbin.com/yigavev/edit?js,console. Can you see if you can reproduce the problem in jsbin (or a similar site), so I can see it in action? – Frank van Puffelen Jul 24 '19 at 13:56
  • thank you for the fiddle! I tested now in the same script plenty times and the issue is not there any more. Strange. I used 6.3.1 and 6.3.0 both then and now. – Fanky Jul 29 '19 at 13:11
  • 1
    I am facing a similar issue but it happens only when longPolling is enabled. You can do it by using firebase.database.INTERNAL.forceLongPolling(). – Glauber Jul 30 '19 at 18:10
  • 1
    I was able to reproduce this one: https://jsbin.com/nasuwem/edit?js,console and it looks like you also filed a bug here: https://github.com/firebase/firebase-js-sdk/issues/2035. Let's follow up on that latter. – Frank van Puffelen Jul 31 '19 at 05:16
  • @Frank van Puffelen, I've just reproduced the issue in your jsbin. It's possible it's dependent on time it's tested / connection, last time I really tested plenty times and all was right, but it was on another wifi. – Fanky Aug 07 '19 at 14:33
  • I can still reproduce this problem with SDK versions 6.0 - 6.3.3. But it has been fixed in [6.3.4](https://firebase.google.com/support/release-notes/js) (I just verified that in the jsbin I shared earlier), so I'd recommend upgrading to that. – Frank van Puffelen Aug 07 '19 at 15:09

1 Answers1

1

This was in issue in a downstream dependency (the JavaScript minifier), which caused encoding problems on some edge cases.

The problem has been solved in version 6.3.4 of the JavaScript SDK, so I recommend upgrading to the latest version if you encounter this problem.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807