Firebase-js-sdk: Encoding Issue with long polling

Created on 30 Jul 2019  路  8Comments  路  Source: firebase/firebase-js-sdk

  • Operating System version: macos Mojave 10.14.5
  • Browser version: Chrome 75.0.3770.142
  • Firebase SDK version: 6.3.3
  • Firebase Product: database

Describe the problem:

Given long polling is enabled, saving strings with an accent (and other non-standard chars) to the realtime database, is throwing an encoding issue.

Steps to reproduce:

  • Import firebase-app and firebase-database from gstatic.
  • Create a project and realtime database.
  • Initialize firebase
  • Enabled long polling
  • Try to write a string like "茅谩茫"

I am not sure if it is a problem with uglifyJs, but one person found out uglifyJs was causing this same issue. But in my example, I am using the minified version provided by Firebase, I am not using uglifyJs.

https://github.com/firebase/firebase-js-sdk/issues/1356
https://github.com/mishoo/UglifyJS2/issues/3278

Relevant Code:

You can see the issue happening here:
https://codepen.io/glauberramos/pen/KOmzRR

firebase.initializeApp(firebaseConfig);
firebase.database.INTERNAL.forceLongPolling();
firebase.database().ref('test/').set('茅帽氓')
database

Most helpful comment

@glauberramos We may have been wrong in regards to how the NPM packages are published.

But we have good news as well: https://github.com/firebase/firebase-js-sdk/pull/2039 will fix this issue as the underlying problem has been fixed in UglifyJs.

All 8 comments

I found a few problems with this issue:

  • I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
  • This issue does not seem to follow the issue template. Make sure you provide all the required information.

I can reproduce the issue, here: https://jsbin.com/nasuwem/edit?js,console

firebase.database.INTERNAL.forceLongPolling();

ref.set("膶esk谩 republika")
   .then(() => console.log("Written") )
   .catch((e) => console.error(e))

ref.on("value", (snapshot) => { console.log(snapshot.val()); })

Running this logs:

"膶esk谩 republika"
"锟斤拷esk锟斤拷 republika"
"Written"

So the first line is the local event, the second line the value from the server, where it is indeed also broken (see json).

Removing the firebase.database.INTERNAL.forceLongPolling() fixes the problem, ruling out issues in the application code.

@glauberramos Thanks for filing this issue. Unfortunately, we are internally using UglifyJs to build our sources, which I believe introduces this problem. Since we have gotten a number of user reports lately, I will get this prioritized again and see if we can find a workaround.

Thanks, @schmidt-sebastian, it will be very nice if you could fix this issue because it is currently affecting users of my product from many countries. From my understanding, it is a critical bug because people cannot write text normally.

If you use uglifyJs version 3.4.8 this issue should not happen. But you probably could test with the latest version as well, I believe the version with issues is 3.4.9.

Is there any non minified version of firebase available?

@glauberramos If you use our NPM packages in your build, you can use the non-minified versions (https://www.npmjs.com/package/firebase)

Thanks @schmidt-sebastian

Where are the non minified version of firebase on NPM package? All files available at root are minified. I am looking at "firebase" module.

@glauberramos We may have been wrong in regards to how the NPM packages are published.

But we have good news as well: https://github.com/firebase/firebase-js-sdk/pull/2039 will fix this issue as the underlying problem has been fixed in UglifyJs.

Was this page helpful?
0 / 5 - 0 ratings