Several issues with JSON encoding in branch DRUPAL-6--1 and alpha releases

mbutcher - October 7, 2008 - 15:56
Project:Views Datasource
Version:6.x-1.0-alpha2
Component:Code
Category:bug report
Priority:normal
Assigned:allisterbeharry
Status:needs review
Description

It appears that the 6.x branch has several issues in the JSON encoding for vanilla JSON data. I haven't looked at the 5 version at all.

1. Output begins: "nodes": [ /* list of objects in here.*/ ]. This is invalid in JSON and JavaScript. Pairs must be part of an object literal.

2. Output uses trailing commas: [{"name": "value", "name2": "value2", },]. This is invalid JSON and JavaScript.

3. strtotime usage has two problems:
a. The check for serialized data assumes that FALSE will be returned when strtotime can't parse. In older PHP versions (prior to 5.1) it returns -1.
b. strtotime is used as a date checker (if strtotime($value) { /* convert to date... */)). But this is bad. It converts a node title like "Last Monday" or "Today" to a date stamp.

I'll submit a patch to fix these three things.

#1

mbutcher - October 7, 2008 - 16:04
Status:active» needs review

Attached is a patch to fix the issues above. In addition, I did the following:

* Fixed a few places where formatting did not accord with the Drupal coding standards.
* Fixed a few doc blocks
* Added a new function that checks to see if a string is a serialized date (returns bool instead of trying to convert)
* Made a minor tweak to the JSON encoding so that it is done in one low-level C call instead of repeated str_replace calls.

I didn't try to do anything all that comprehensive... just got it working for what I need.

The patch was generated against CVS branch DRUPAL-6--1, which I presume is the current latest branch. It applied cleanly to the alpha2 release, as well. (Note that I tested it against an older version of Views2, having seen bugs about the recent Views 2 changes.)

Thanks for building this module. It is very useful.

AttachmentSize
views_datasource-318130_00.patch 6.28 KB

#2

mbutcher - January 30, 2009 - 02:07

I see there has been no movement on this patch.

I think there is an even simpler solution than the one I provided above, since the drupal_to_js() function accomplishes the goal of entire functions in the views_datasource plugin.

I would be more than happy to submit another patch... but is this module even being maintained at this point?

#3

allisterbeharry - October 10, 2009 - 21:00
Assigned to:Anonymous» allisterbeharry

Thanks for the patch - I'll incorporate the date check and the more efficient JSON encoding in the next release. Docs and code formatting are a project-wide issue I have to work on.

 
 

Drupal is a registered trademark of Dries Buytaert.