Originally reported here: http://drupal.org/node/1030334#comment-4211048

When I try to browse Content (section) > Content (vertical tab), the app quits unexpectedly EVERY time.

@anavarre can you be a bit more precise, please. I can't reproduce for now.

From the main screen what does crash:

  • Content
  • or inside Content switching between Published and Not published
  • Browse site

Can you tell me: iOS version, iPhone/iPodTouch version (3, 3G, 3Gs, 4, iPad, etc.)

Does your device still have free space?

Thanks,
Jérémy

PS: marking as coming from the app for now even though I have no idea :-)

Comments

anavarre’s picture

From the main screen, the App crashes when selecting Content, then trying to retrieve the Published or Not published content.

I have an iPhone 4 with iOS 4.3 and tons of free space.

jchatard’s picture

Crap... I do have an iPhone 4, iOS 4.3, plenty of free space too, and it works.

Can you:

This should output OR download a file containing JSON formatted data.

Do you notice anything strange?

anavarre’s picture

I've just commented line 81 in drupad.module

// return FALSE;

http://yoursite.com/?q=drupad/content&status=1&page=1 gives a looong output
http://yoursite.com/?q=drupad/content&status=0&page=1 gives a short output

There is nothing that seems wrong at this stage

jchatard’s picture

Any reported error by validating those outputs with http://www.jsonlint.com ?

anavarre’s picture

JSONLint says I have Valid JSON for the short output but I have errors on the long output.

When I copy/paste the output to JSONLint it says :

syntax error, unexpected $end at line 66
Parsing failed

When I enter the URL, it says :

URL returned bad status code 401.

I'm not sure it has actually errors. Maybe the output is too big for the online tool ? What do you think ?

jchatard’s picture

The URL returns a code 401 because to access this URL you need to be authenticated, so your web server asks JSONLint a login and a password. So this 401 code is totally the expected behavior.

You seem to have an error in the returned JSON.

Can you send me an excerpt of your output? To see what this 66 line looks like.

anavarre’s picture

Actually, JSONLint tries to parse the file, formats it well, then stops at line 66, giving this line the rest of the long output as raw text as if the output was too big to parse.

When I try to reformat the code from line 66 to the next curly bracket, it valids just fine.

Sample :

{
    "content": [
        {
            "nid": "46",
            "vid": "46",
            "type": "forum",
            "language": "en",
            "title": "My new topic",
            "uid": "121",
            "status": "1",
            "created": "1294045859",
            "changed": "1294045859",
            "comment": "2",
            "promote": "0",
            "sticky": "0",
            "tnid": "0",
            "translate": "0",
            "username": "jdoe",
            "mail": "jdoe@jdoe.com",
            "content_type": "Topic",
            "picture": "http:\/\/www.mysite.com\/sites\/default\/files\/pictures\/picture-121-1293635305.png",
            "teaser": "\u003cdiv id=\"node-46\" class=\"node node-forum clearfix\" about=\"\/topic\/my-new-topic\" typeof=\"sioc:Post sioct:BoardPost\"\u003e\n\n        \u003ch2 property=\"dc:title\" datatype=\"\"\u003e\n      \u003ca href=\"\/topic\/my-new-topic\"\u003eMy new topic\u003c\/a\u003e\n    \u003c\/h2\u003e\n    \n      \u003cdiv class=\"meta submitted\"\u003e\n        \u003cdiv class=\"user-picture\"\u003e\n    \u003ca href=\"\/users\/jdoe\" title=\"User profile.\"\u003e\u003cimg typeof=\"foaf:Image\" src=\"http:\/\/www.mysite.com\/sites\/default\/files\/styles\/thumbnail\/public\/pictures\/picture-121-1293635305.png\" alt=\"jdoe profile\" title=\"jdoe profile\" \/\u003e\u003c\/a\u003e  \u003c\/div\u003e\n      \u003cspan property=\"dc:date dc:created\" content=\"2011-01-03T10:10:59+01:00\" datatype=\"xsd:dateTime\" rel=\"sioc:has_creator\"\u003epubli\u00e9 par \u003ca href=\"\/users\/jdoe\" title=\"User profile.\" class=\"username\" xml:lang=\"\" about=\"\/users\/jdoe\" typeof=\"sioc:UserAccount\" property=\"foaf:name\"\u003ejdoe\u003c\/a\u003e le lun, 03\/01\/2011 - 10:10\u003c\/span\u003e    \u003c\/div\u003e\n  \n  \u003cdiv class=\"content clearfix\"\u003e\n    \u003cdiv class=\"field field-name-body field-type-text-with-summary field-label-hidden\"\u003e\u003cdiv class=\"field-items\"\u003e\u003cdiv class=\"field-item even\" property=\"content:encoded\"\u003e\u003cp\u003eHello,\u003cbr \/\u003e\nThis is a test.\u003cbr \/\u003e\nThanks.\u003cbr \/\u003e\n\u003c\/p\u003e\n\u003c\/div\u003e\u003c\/div\u003e\u003c\/div\u003e  \u003c\/div\u003e\n\n  \n  \n\u003c\/div\u003e\n",
            "language_full": "Enligsh" 
        }
    ]
}
jchatard’s picture

The expected full format is as follow for 2 nodes:

{
    "content": [
        {
            "nid": "2",
            "vid": "2",
            "type": "article",
            "language": "und",
            "title": "This is another article",
            "uid": "0",
            "status": "1",
            "created": "1300253978",
            "changed": "1300253978",
            "comment": "2",
            "promote": "1",
            "sticky": "0",
            "tnid": "0",
            "translate": "0",
            "username": "Anonymous",
            "mail": "",
            "content_type": "Article",
            "teaser": ".... JSON escaped HTML content here..."
        },
        {
            "nid": "1",
            "vid": "1",
            "type": "article",
            "language": "und",
            "title": "This is an article",
            "uid": "1",
            "status": "1",
            "created": "1294731196",
            "changed": "1294731196",
            "comment": "2",
            "promote": "1",
            "sticky": "0",
            "tnid": "0",
            "translate": "0",
            "username": "admin",
            "mail": "john@doe.com",
            "content_type": "Article",
            "teaser": ".... JSON escaped HTML content here..."  // <---- might be here
        }
    ],
    "meta": {
        "total_count": "2"
    }
}

Side note: you need the ending "meta" > "total_count".

My guess is you may have something wrong in the teaser property of one of the node (HTML), which causes JSONLint to think it's the end of the object (but too early).

Try to validate this structure with the node which is at line 66. Also try to inspect the teaser value of this node (and/or all properties). We need to know why JSONLint can't validate it.

anavarre’s picture

OK, thank you for the info about the JSON format, now I understand the structure.

The first element on line 66 that gives an error is indeed related to the teaser part of a forum topic. Just to be sure, I've hidden all teaser fields for the topic content type. Unfortunately nothing better comes from this modification.

I've played again with JSONLint (nice tool !) and I've pruned many nodes by keeping the expected JSON output structure. The result is I've also had errors on the teaser part for other content types than "topic". For them, I just can't try and hide the teaser as it's used in production...

What if it was something in Drupal JSON teaser handling ?

jchatard’s picture

If you send me by mail a teaser of a failing node (like one of your forum topic) I could try to have a look and maybe determine which chars aren't well encoded (as they are expected to for JSON).

All the JSON conversion is handled by drupal_json_output() (line 202 of the .module).

Which in fact lets PHP itself convert data to JSON.

So this doesn't look like a Drupal issue.

anavarre’s picture

Thank you for that. The one in #7 is a real (forum) node. I've just replaced the user/title/message/website infos by dummy text.

jchatard’s picture

#7 validates actually!

And code from #7 integrated in my Drupal 7 instance - as if this was from my website - shows up correctly in my app with no crash.

2 solutions:

  • either user and/or title and/or message and/or website are not valid/correctly escaped
  • or JSONLint Validator isn't doing its job for big (but not so big) chunks of JSON, and obviously we are not looking in the right direction

Other JSON validator/tools:

http://jsonformatter.curiousconcept.com/
http://labs.gerbenrobijn.nl/code-examples/json/jsonvalidator.html
http://jsonviewer.stack.hu/

anavarre’s picture

Solution 2 is the correct one ! JSONLint Validator doesn't do (all) the job. I got my code validated from the other tools. The funny thing is JSONLint doesn't like raw formatting. Actually it validates the big output only when the code is formatted...

jchatard’s picture

Ok,

I need to reproduce the bug form my computer to inspect the stack trace of the app.

Would you be able to create an account for me (only for testing purposes) which would allow me to access your site from my iPhone?

anavarre’s picture

Thank you, I've just sent a PM where you'll have all necessary informations.

BenK’s picture

Subscribing

anavarre’s picture

Status: Active » Fixed

So I've created an access for Jérémy, everything worked for him but not for me. He then advised to reinstall the app as a final test...and it worked. I don't know what happened but this doesn't seem to be Drupad specific at all.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.