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 :)
| Attachment | Size |
|---|---|
| custom_breadcrumbs_operators.patch | 767 bytes |

#1
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.
#2
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
Fixed in CVS, will be part of the 1.3 release. Thanks!
#4