Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if data is an object in loadRemote. #206

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

pokono
Copy link

@pokono pokono commented Jul 15, 2015

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 pokono changed the title Master Check if data is an object in loadRemote. Jul 16, 2015
@rubenv
Copy link
Owner

rubenv commented Jul 17, 2015

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.

@hynek-urban
Copy link

@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.

@pokono
Copy link
Author

pokono commented Jul 29, 2015

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

@pokono
Copy link
Author

pokono commented Sep 2, 2015

@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.

@@ -286,8 +286,10 @@ angular.module('gettext').factory('gettextCatalog', function (gettextPlurals, ge
cache: catalog.cache
}).then(function (response) {
var data = response.data;
for (var lang in data) {
catalog.setStrings(lang, data[lang]);
if (typeof data === 'object') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would check the response type tbh

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hear what you are saying, but in this case the response would be an object and the status would be a 200 too. See the screenshot below.
I am willing to put in more work into this but I need some guidance from you guys.
screen shot 2017-03-10 at 2 18 06 pm

@alfaproject
Copy link
Contributor

alfaproject commented Mar 10, 2017

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

@pokono
Copy link
Author

pokono commented Mar 10, 2017

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.

…the content. This avoid parsing data that is not useful, like in situations where pinging a file that doesn’t exist return index.html.
@pokono pokono reopened this Mar 10, 2017
@alfaproject
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants