Ticket #810 (closed defect: fixed)
Filter on username can't work for registered users
| Reported by: | JavaWoman | Owned by: | BrianKoontz |
|---|---|---|---|
| Priority: | normal | Milestone: | 1.3.1 |
| Component: | unspecified | Version: | 1.1.6.5 |
| Severity: | normal | Keywords: | trunk-ported |
| Cc: |
Description
Both LoadRecentComments() and LoadRecentlyCommented() have an option to filter on comments by a specified user (by name) only. For admins, this works, for registered user it can't, although this is clearly intended to work. (I think this bug has been around since 1.1.6.4.)
The reason is that these functions expect a username as parameter, but the check for a registered user compares this to the user array in the session. That comparison will always fail, so a registered user will not be able to specify to see only their own comments.
The root cause is a sloppy use of parameter names: sometimes $user is used to signify the whole array of user data (as stored in the DB and the session of a logged-in user), and sometimes to signify just a username. The best defense against this is to always use '$username' when a function (etc.) actually wants just a name, and always use '$user' when a function expects the whole data array.
The fix in these two functions is to:
- use $username as the parameter name
- use the following construct like this to filter on a specific user only:
$curuser = $this->GetUser(); if (!empty($username) && ($username == $curuser['name'] || $this->IsAdmin())) { $where = "WHERE `user` = '".mysql_real_escape_string($username)."' "; }