Incorrect logic for link verification

quicksketch - April 22, 2007 - 08:48
Project:Custom Breadcrumbs
Version:5.x-1.2
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:closed
Description

This module is so easy to use, I love it.

It seems for some reason the order of operators in this statement executes inconsistently (I can't explain why):

<?php
         
// Output plaintext instead of a link if there is a title
          // without a path.
         
if ($path = trim($paths[$i]) && $path != '<none>') {
           
$trail[] = l($title, trim($paths[$i]));
          }
          else {
           
$trail[] = check_plain($title);
          }
?>

The "correct" order of operation in $path = trim($paths[$i]) && $path != '<none>' would be:
- $path != '<none>'
- trim($paths[$i]) && [result from above]
- $path = [result from above]

See http://www.php.net/manual/en/language.operators.php#language.operators.p...

So the real question is why it ever works at all :)

AttachmentSize
custom_breadcrumbs_operators.patch767 bytes

#1

dkruglyak - August 4, 2007 - 21:27
Title:Incorrect operator order eats links» Incorrect logic for link verification
Status:patch (code needs review)» patch (reviewed & tested by the community)

Original logic is wrong. The link should be dropped only if the path is trimmed to nothing, not that any trimming occurs - which could be a by-product of Token module (e.g. when you have blog/[author-uid])

My modified patch is tested and ready to go.

AttachmentSize
custom_breadcrumbs.patch812 bytes

#2

andyschm - August 23, 2007 - 22:14

According to that page, && is higher precedence than =, but the equivalent logical operator "and" is lower precedence... bizarre!

Anyways the above patch fixed the problem for me.

In my opinion the use of assignment in conditionals is confusing and should discouraged in general.

#3

Eaton - August 25, 2007 - 06:01
Status:patch (reviewed & tested by the community)» fixed

Fixed in CVS, will be part of the 1.3 release. Thanks!

#4

Anonymous - September 8, 2007 - 06:11
Status:fixed» closed
 
 

Drupal is a registered trademark of Dries Buytaert.