Token types handler bug

dagmar - January 17, 2009 - 21:16
Project:Custom Tokens
Version:6.x-1.1
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:closed
Description

Hello:

I try to use this module with filefield and filefield_paths and I have discovered a small, but important bug.

I create some node custom tokens.
Filefield try to replace the user tokens from the file path. This function

<?php
function token_custom_token_values($type, $object = NULL, $options = array()) {

 
$result = db_query("SELECT * FROM {token_custom}");
  while (
$row = db_fetch_object($result)) {
    switch (
$row->type) {
      case
'taxonomy':
      case
'node':
      case
'comment':
      case
'user':
       
$tokens[$row->id] = _token_eval($row->php, $row->type, $object);
        break;
      default:
       
$tokens[$row->id] = _token_eval($row->php, $row->type);
        break;
    }
  }

  return
$tokens;
}
?>

Will execute the php code for the node token, and because the code is expecting a node, it returns an empty value. But an empty value is a valid value for replace a token. Then, the node token is replaced by an empty string and it would not be processed later.

I don't know if this issue is valid for the 5.x version.

Sorry for my english

AttachmentSize
token_custom_d6.patch556 bytes

#1

hanoii - January 19, 2009 - 13:29
Status:needs review» fixed

Nice catch. I have fixed this in a slightly different way from your patch, but thanks for submitting it.

I should also mention that you have a variable $type available on your PHP code that holds the type of the token).

a.=

#2

System Message - February 2, 2009 - 13:30
Status:fixed» closed

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

 
 

Drupal is a registered trademark of Dries Buytaert.