angular-gettext icon indicating copy to clipboard operation
angular-gettext copied to clipboard

Check if data is an object in loadRemote.

Open pokono opened this issue 9 years ago • 7 comments

Added data === 'object' to check if data is an object before parsing
 the content. This avoid parsing data that is not useful, like in situations where pinging a file that doesn’t exist return a index.html file.

If this is not present may happen that the code parse data for minutes. At least this was happening to me. Any suggestions welcome ;)

pokono avatar Jul 15 '15 22:07 pokono

Do you have an example of a jsFiddle that demonstrates this problem? There's no parsing happening in the code you're referencing, just a simple property loop.

rubenv avatar Jul 17 '15 05:07 rubenv

@rubenv I've actually come here to report the same problem. Seeing this thread, I have tried to produce a jsfiddle example but in the contrived setting of jsFiddle, I failed to do so.

However, I can confirm that I have experienced problems with the same portion of code that @pokono has patched.

The loadRemote function parameter is an url, but it can be an url that returns something else than JSON - as pokono wrote, it could be an index.html file. In that case the loop doesn't actually loop over object properties, but over indices of a (potentially very long) string. That has exactly happened to me because of a misconfigured proxy, resulting in strangely displayed text captions (concatenated multiple times), eventually leading to a browser crash.

As soon as the url was properly configured to serve a json file with translations, the problem disappeared. It wasn't so easy to figure out what's wrong, though.

Anyway, sorry for not being able to reproduce it in a test environment, but I hope you'll find this relevant anyway.

hynek-urban avatar Jul 28 '15 14:07 hynek-urban

@rubenv I'll provide a test case, so you can check it out. I just haven't had the time yet!

pokono avatar Jul 29 '15 16:07 pokono

@WWuzzy @rubenv I created a JSFiddle to show the issue here: https://jsfiddle.net/pokono/zj8v65f3/17/. Just run it and look at the console, I'm printing everything that is parsed there. This is what happen with the changes I did, nothing is parsed unless is an object. https://jsfiddle.net/pokono/7fqgyr9n/13/

I hope this helps. Please let me know if I can be of any help here.

EDIT: I updated the last example with the latest code.

pokono avatar Sep 02 '15 21:09 pokono

Can you squash the commits? A bit too verbose for a ~1 line change

alfaproject avatar Mar 10 '17 08:03 alfaproject

I will squash the commits when we're getting to the final result that we want. Do you have any idea of why is failing the tests? I was trying to understand but I didn't yet.

pokono avatar Mar 10 '17 19:03 pokono

Not sure to be honest, but it doesn't look related to your change. o:

alfaproject avatar Mar 11 '17 17:03 alfaproject