Hi,

I have a very subtle low level bug to report. It only occurs under very specific circumstances, but you may want to correct it anyway because it's fairly deep and if it arises in some other way in the future, it is not easy to track down.

Description of cause:

The Activity module has many sub modules (ie. nodeactivity, commentactivity) which define hook_token_values(). Most (or all) of these functions add extra elements to the $data parameter and return $data. Hence, these functions are also returning duplicate token values.

ie. commentactivity_token_values() returns values for the tokens comment-cid, parent-node-title, parent-node-type etc. which it actually doesn't know anything about.

My hypothesis is: These functions are incorrect. They should not be returning duplicate token values.

Reproduction of issue:

If the functions return duplicate token values, under certain conditions, the token values get corrupted.

To reproduce this problem, you need a separate module that defines hook_token_values() and does the following:

function your_module_token_values($type, $data = NULL, $options = array()) {
  if ($type == 'commentactivity') {
    if (!empty($data)) {
    
      /* Add some code here that adds extra token values to $data */
    
      return $data;
    }
  }
}

(In practice, I ran across this bug because I was writing a custom module that added some extra tokens to the token class 'commentactivity'.)

There needs to be at least two functions that add duplicate tokens to the same token class. The sub modules (ie. commentactivity) already define one. When there are two or more, then the token values get corrupted because of an array_merge_recursive() (called from module_invoke_all() called from token_get_values() from token.module).

Instead of a dump of token values like this:

stdClass Object
(
    [tokens] => Array
        (
            [0] => user-name
            [1] => user-id
            [2] => user-mail
            [3] => site-url
            [4] => site-name
            [5] => site-slogan
            [6] => site-mission
            [7] => site-mail
            [8] => site-date
            [9] => comment-cid
            [10] => comment-subject
            [11] => parent-node-author-uid
            [12] => parent-node-id
            [13] => parent-node-title
            [14] => parent-node-type
            [15] => aid
            [16] => uid
            [17] => module
            [18] => type
            [19] => operation
            [20] => created
            [21] => comment-link
            [22] => parent-node-author
            [23] => parent-node-author-name
            [24] => parent-node-link
        )

    [values] => Array
        (
            [0] => admin
            [1] => 1
            [2] => root@localhost
            [3] => http://withheld
            [4] => withheld
            [5] => 
            [6] => 
            [7] => withheld
            [8] => Wed, 06/24/2009 - 10:49pm
            [9] => 70
            [10] => Test comment 3.
            [11] => 7
            [12] => 67
            [13] => withheld
            [14] => withheld
            [15] => 268
            [16] => 7
            [17] => commentactivity
            [18] => comment
            [19] => update
            [20] => 1245830032
            [21] => Test comment 3.
            [22] => withheld
            [23] => withheld
            [24] => withheld
        )

)

You get something like this:

stdClass Object
(
    [tokens] => Array
        (
            [0] => user-name
            [1] => user-id
            [2] => user-mail
            [3] => site-url
            [4] => site-name
            [5] => site-slogan
            [6] => site-mission
            [7] => site-mail
            [8] => site-date
            [9] => comment-cid
            [10] => comment-subject
            [11] => parent-node-author-uid
            [12] => parent-node-id
            [13] => parent-node-title
            [14] => parent-node-type
            [15] => aid
            [16] => uid
            [17] => module
            [18] => type
            [19] => operation
            [20] => created
            [21] => comment-link
            [22] => parent-node-author
            [23] => parent-node-author-name
            [24] => parent-node-link
        )

    [values] => Array
        (
            [0] => admin
            [1] => 1
            [2] => root@localhost
            [3] => withheld
            [4] => withheld
            [5] => 
            [6] => 
            [7] => withheld
            [8] => Wed, 06/24/2009 - 10:47pm
            [9] => Array
                (
                    [0] => 70
                    [1] => 70
                )

            [10] => Array
                (
                    [0] => Test comment 3.
                    [1] => Test comment 3.
                )

            [11] => Array
                (
                    [0] => 7
                    [1] => 7
                )

            [12] => Array
                (
                    [0] => 67
                    [1] => 67
                )

            [13] => Array
                (
                    [0] => withheld
                    [1] => withheld
                )

            [14] => Array
                (
                    [0] => withheld
                    [1] => withheld
                )

            [15] => Array
                (
                    [0] => 268
                    [1] => 268
                )

            [16] => Array
                (
                    [0] => 7
                    [1] => 7
                )

            [17] => Array
                (
                    [0] => commentactivity
                    [1] => commentactivity
                )

            [18] => Array
                (
                    [0] => comment
                    [1] => comment
                )

            [19] => Array
                (
                    [0] => update
                    [1] => update
                )

            [20] => Array
                (
                    [0] => 1245830032
                    [1] => 1245830032
                )

            [21] => Test comment 3.
            [22] => withheld
            [23] => withheld
            [24] => withheld
        )

)

The second dump is obviously incorrect. All those values defined by hook_token_values() functions which return duplicate token values get transformed into an array by array_merge_recursive(). This results in corrupted data.

Also, my testing was against an older version of 6.x-1.x-dev, but as of writing, the latest code on the DRUPAL-6--1 branch still has this issue.

Thank you.

Comments

sirkitree’s picture

Status: Active » Closed (won't fix)

closing. 1.x no longer supported.