A very interesting edge case

Wouter - July 23, 2008 - 14:36
Project:Views Datasource
Version:5.x-1.0-alpha2
Component:Code
Category:bug report
Priority:normal
Assigned:allisterbeharry
Status:active
Description

Hi !

First of all thanks for this great module. Even in its alpha stages, it's already proving to be very useful for us.

I have an interesting problem you might want to take a look at.

I am using a JSON view to output a couple of fields of a selection of nodes. I use the JSON view in some JQuery code to fetch these nodes.

One of the fields I have is a name field, in which artist's names are entered. For one of the records the value for this field happens to be "JAN (B)"

Can you see it coming ?

Well for the normal JSON view : no probs. But when I switch to the MIT Simile JSON view, the JAN value pops out in the JSON output as :

"%2008-%01-%22 %23:%Jan:%nd"

I expect the module triest to convert the 'JAN' string somehow, for a probably very good reason. Alas this shouldn't happen of course.

Thought i'd mention it here, so you can put it on the list :)

#1

Wouter - July 23, 2008 - 14:46

digging a bit in the module and most probably it'll be these few lines of code that are the ones causing my issue :

Line 201

if (strtotime($value))
        $value = date(EXHIBIT_DATE_FORMAT, strtotime($value));
    $value = views_json_encode_special_chars($value);

#2

allisterbeharry - April 14, 2009 - 22:29
Assigned to:Anonymous» allisterbeharry

Yes you're right - changing this to:

      if (preg_match('/\d/', $value)) {
        if (strtotime($value))
          $value = date(EXHIBIT_DATE_FORMAT, strtotime($value));
      }

should be ok at least for this edge case as it won't attempt to do any date conversion if there are no numbers in the value. It's not a complete solution because there may be instances where letters and numbers may co-mingle to give the appearance of a date to strtotime.

#3

jcamfield - May 11, 2009 - 14:49

This also shows up for Lat/Long data in the XML; I think the regex needs to be a bit more strict, as strtotime will try pretty hard to make any number into a date/time string :)

If I get a free moment this week I'll try some regex-fu to filter dates

 
 

Drupal is a registered trademark of Dries Buytaert.