ElkArte Community

Elk Development => Bug Reports => Exterminated Bugs => Topic started by: Xarcell on June 18, 2013, 07:12:35 pm

Title: "New" Not Showing Properly
Post by: Xarcell on June 18, 2013, 07:12:35 pm
On this topic: http://www.elkarte.net/index.php?topic=443.30

It doesn't not show me the "new" tag beside any topics in the MessageIndex, but the BoardIndex it is in(Site Feedback) shows as bold(as in new topic/reply).

Other topic in other boards have the "new" label if there is a new topic/reply.
Title: Re: "New" Not Showing Properly
Post by: emanuele on June 18, 2013, 07:29:19 pm
Yep, noticed, but I didn't have time to debug it (I was breaking other things :P).

I think it is the first time you enter a board (i.e. if you have two boards with unread messages, the first you enter doesn't give the "new" message, while the others do), but I'm not 100% sure.
If it is so, it may be related somehow to the session.
Title: Re: "New" Not Showing Properly
Post by: Xarcell on August 25, 2013, 10:08:49 pm
I haven't been as involved with the community since this issue. It seems this issue is still there. I don't visit everyday so I can't tell which posts are new per topic or not.
Title: Re: "New" Not Showing Properly
Post by: emanuele on August 26, 2013, 04:28:55 am
Yep, still there.
I think (not sure though) it has been solved in the repo, but the site is kind of outdated... O:-)
Title: Re: "New" Not Showing Properly
Post by: Xarcell on August 30, 2013, 12:21:23 pm
Seems to be fixed now. Thanks.
Title: Re: "New" Not Showing Properly
Post by: emanuele on September 23, 2013, 12:35:33 pm
It's fixed on the site, but is still broken in the code.
The issue is in the  Request class, where $_REQUEST['start'] is always considered an integer, while in few places it is not.
Title: Re: "New" Not Showing Properly
Post by: Spuds on September 23, 2013, 01:45:04 pm
If you want I'll make a PR for that ... but basically I removed that limitation vs change all the code to enforce that limitation.  Otherwise we can wait for Norv to have some free time since that was her code change and she should know best which direction.
Title: Re: "New" Not Showing Properly
Post by: emanuele on September 23, 2013, 03:00:41 pm
I don't know exactly where put my hands to fix it "properly", mostly because there are at least two "exceptions" (to the (int) rule) and both are slightly different as far as I've seen, so they would require an ad hoc implementation of the cleanup.

If the do-not-cast-to-int is enough for now, I can push it to the branch I have open or if you want feel free to push it in your PR! :P

/me likes the second option because is less work for him. :P
Title: Re: "New" Not Showing Properly
Post by: Spuds on September 23, 2013, 03:08:45 pm
Feel free to make the PR :) ... for now I'd go with the do not cast solution since as you noted, the other fixes are quite a bit more involved and lets face it, its been un-cast for a heck of a long time  O:-)  (Does not mean its proper, just that it does not seem harmful)
Title: Re: "New" Not Showing Properly
Post by: emanuele on September 23, 2013, 03:23:30 pm
https://github.com/emanuele45/Dialogo/commit/329518e18fa6d25d01baa799ccf0b49b73b10e5b

Commented out only for Display, because apparently all the others are int...apparently.
Title: Re: "New" Not Showing Properly
Post by: Spuds on September 23, 2013, 04:27:19 pm
Does it need to be set to zero if its not set ?  What I did on the site was:
Code: [Select]
$_REQUEST['start'] = isset($_REQUEST['start']) ? $_REQUEST['start'] : 0;

Title: Re: "New" Not Showing Properly
Post by: emanuele on September 23, 2013, 04:35:47 pm
There is a check (luckily, I didn't see it at first :P) at line 262 (https://github.com/emanuele45/Dialogo/blob/master/sources/Request.php#L262) that seems to take care of that. O:-)
Title: Re: "New" Not Showing Properly
Post by: Spuds on September 23, 2013, 04:39:57 pm
 8)
Title: Re: "New" Not Showing Properly
Post by: [SiNaN] on September 23, 2013, 08:27:54 pm
Maybe you could have a little regex for that. I don't remember the exceptions but something like this:

$_REQUEST['start'] = isset($_REQUEST['start']) && preg_match('~^(:?(:?from|msg)?\d+|new)$~', $_REQUEST['start']) ?  $_REQUEST['start'] : 0;

A little test code too, if you can think of more cases:

Code: [Select]
<?php

$regex = '~^(:?(:?from|msg)?\d+|new)$~';

$tests = array(
 '123' => 1,
 'new' => 1,
 'msg123' => 1,
 'from123' => 1,
 '123msg' => 0,
 'from12x3' => 0,
 'new123' => 0,
 'news' => 0,
 'msg1.23' => 0,
);


echo '
<style>
table
{
 border-collapse:collapse;
}
td, th
{
 border: 1px solid #000;
 padding: 0.5em;
}
</style>
<table>
 <tr>
 <th>Test</th>
 <th>Expected</th>
 <th>Result</th>
 </tr>';

foreach ($tests as $test => $expected)
{
 $result = preg_match($regex, $test);
 echo '
 <tr>
 <td>', $test, '</td>
 <td>', $expected, '</td>
 <td>', $result, '</td>
 </tr>';
}

echo '
</table>';

Reminds me of the time we were coding compareVersions() and matchPackageVersion() functions right before 2.0 release with Norv and came up with 100+ cases to test. Good old days...


That turned out to be a pretty weird check but interestingly it actually prevented a PHP bug to be exploited.
Title: Re: "New" Not Showing Properly
Post by: emanuele on September 25, 2013, 08:19:36 am
Thanks [SiNaN]!
Will try for sure.
I don't know exactly all the exceptions me either, but if we find some we can add them to the list. :P

Quote from: [SiNaN] – That turned out to be a pretty weird check but interestingly it actually prevented a PHP bug to be exploited.
Norv wrote it, you can't expect anything less than weird checks. :P
Title: Re: "New" Not Showing Properly
Post by: [SiNaN] on September 25, 2013, 09:19:26 am
Quote from: emanuele – Thanks [SiNaN]!
Will try for sure.
I don't know exactly all the exceptions me either, but if we find some we can add them to the list. :P

They are probably all there is, from what I can see in the part related to the handling of start variable in Display controller. But, yeah, you'll know for sure once people start complaining about it, lol.

Quote from: emanuele – Norv wrote it, you can't expect anything less than weird checks. :P

Actually it was me who wrote that, lol. I was tempted to pretend to know nothing but felt sorry for Norv...
Title: Re: "New" Not Showing Properly
Post by: emanuele on September 25, 2013, 09:22:13 am
ohhh... lol
Then you are as weird as Norv and I didn't know. :P
Title: Re: "New" Not Showing Properly
Post by: [SiNaN] on September 25, 2013, 10:13:44 am
May I take that as a compliment? :P And that explains why we got along so well with Norv. lol
Title: Re: "New" Not Showing Properly
Post by: emanuele on October 08, 2013, 03:10:08 pm
Committed locally.