I didn't test but looking at it looks like it doesn't do anything.

inside user.module:

/**
 * Implementation of hook_comments().
 */
function user_comment($comment, $op) {
  // Validate signature.
  if ($op == 'view') {
    if (variable_get('user_signatures', 0) && !empty($comment->signature)) {
      $comment->signature = check_markup($comment->signature, $comment->format);
    }
    else {
      $comment->signature = '';
    }
  }
}

Is it supposed to return something or does $comment have to be passed into the function as a reference?

Comments

gábor hojtsy’s picture

As far as I see, this gets invoked with comment_invoke_comment($comment, 'view') (without caring about the return value), and comment_invoke_comment() takes $comment by reference and passes it on, so user_comment() can modify it. This code also needs a fix in the function comment, as far as I see.

dvessel’s picture

Priority: Normal » Critical

But nothing is passed by reference here. This looks dangerous. Marking as critical.

dvessel’s picture

Status: Active » Closed (works as designed)

err, sorry about that.

Finally checked and it isn't an issue. I'm quite baffled on how this works.

dvessel’s picture

Priority: Critical » Normal
Status: Closed (works as designed) » Reviewed & tested by the community
StatusFileSize
new465 bytes

Okay, one more time. Checked the output of comment_invoke_comment(). With user_comment() returning nothing comment_invoke_comment also returns nothing.

This patch just returns a value for user_comment making comment_invoke_comment work as expected.

The signature is getting cleaned up elsewhere before output under comments which confused me.

dvessel’s picture

Title: signature cleanup not happening in user_comment() » hook_comment returns empty due to user_comment

More appropriate title?

gábor hojtsy’s picture

Status: Reviewed & tested by the community » Needs work

Well, my observations above showed that &$comment should be used, as we get the comment to modify. Trace through the path I explained. The function also needs a fix in the phpdoc comment.

dvessel’s picture

Okay, I see now that it has to be passed as reference in "user_comment(&$comment, $op)". It looks like it's optional depending on what the hook is doing.

But this is really bizarre. Even when *not* passing as reference, it gets cleaned. I even tried removing the reference inside comment_invoke_comment just to see and it still gets cleaned. Also tried removing user_comment. It didn't clean the sig so that tells me that that's the only place it's cleaning up the sig..

I think I'll leave this one alone. I didn't think this was possible.

dvessel’s picture

Priority: Normal » Critical
Status: Needs work » Reviewed & tested by the community
StatusFileSize
new635 bytes

You were right Gábor Hojtsy, but I didn't know why. I just learned that objects always gets passed by reference in these cases for PHP5.

So here it is so it'll work in php4 also.

dvessel’s picture

StatusFileSize
new678 bytes

Whoops, phpdoc fixed.

gábor hojtsy’s picture

Status: Reviewed & tested by the community » Fixed

Thanks, committed!

Anonymous’s picture

Status: Fixed » Closed (fixed)