Hi,

I've just destroyed half an hour's work the second time, because a special PHP code makes the view be reset to initial state, i.e. with no fields, no settings etc.

To reproduce,

  • create a view with some fields
  • save view
  • add a custom field of type PHP and enter the following code:
    <?php
    $body = $data->node_revisions_body;
    $pattern = '/<a.*?href="(.*?)".*?>(.*?)<\/a>/';
    $matches = array();
    preg_match_all($pattern, $body, $matches);
    foreach ($matches[0] as $match) {
      print check_plain($match);
    }
    ?>
    
  • save view.

In my case, after saving the view, it is reset to initial state. When changing the view, the preview looks fine.

This is PostgreSQL and while saving, I can see the (pgsql-typical?) errors "PHP Notice: unserialize(): Error at offset 0 of 30 bytes in .../trunk/includes/bootstrap.inc on line 555, referer: https://.../trunk/admin/build/views/edit/testview" in my Apache error log multiple times.

Anyone can reproduce this?

Tobias

Comments

tpfeiffer’s picture

The code above contains an error, the opening single quote for $pattern is missing; it was apparently stripped away by this text field when posting. The bug report was for the version with the missing single quote.

tpfeiffer’s picture

OK, the reason for this seems to be my backslash in the regular expression /<a.*?href="(.*?)".*?>(.*?)<\/a>/. If i replace the regexp delimiter / by _ (which means I don't have to escapt the forward slash in </a>), i.e. _<a.*?href="(.*?)".*?>(.*?)</a>_, this problem doesn't occur any more.
However, if possible, this should be fixed anyway.

SeanA’s picture

Title: custom PHP field resets view to initial state » Backslashes in custom PHP field resets view to initial state

I experienced the same problem -- the view resets to the initial state, removing all filters, fields, etc -- when saving the view after adding a custom php field. After losing my work the first time I started exporting the view before attempting to save it. The offending code:

$description = explode("\n", $data->term_data_description);
echo $description[0];

If I add the field and export the view before saving, the code stored like this in the exported view:

'value' => '<?php
$description = explode("\\n", $data->term_data_description);
echo $description[0];
?>'

Yes, something funky is going on with escaping backslashes. This site is also on PostgreSQL. No time right now to investigate further.

(What I was trying to do is display just the first line of the term description. My workaround was to just eliminate this custom field and use the whole description, which happens to work just fine in this case.)