mywot / chrome

WOT's Chrome extension
http://www.mywot.com/wiki/Chrome
GNU General Public License v3.0
8 stars 7 forks source link

Search results missing a rating symbol for unrated sites sometimes #5

Closed samitolvanen closed 12 years ago

samitolvanen commented 12 years ago

When a site doesn't have a reputation, wot.geticon called from wot.search.getcss sometimes returns this URL:

chrome-extension://bhmmomiinigofkjcapegjjndpbikblnp/skin/fusion/16_16/plain/undefined.png

Apparently the r parameter is undefined, which results in an invalid URL and no rating icon next to the search result. How does this happen...?

Edit: Good news, I can't reproduce it. Seems to happen randomly.

sorgoz commented 12 years ago

What Chrome version do you use?

samitolvanen commented 12 years ago

18.0.1025.7 dev

Although I have seen this before, but never actually looked at why the rating symbol is missing. If it helps, here's what I did:

  1. Searched for a website that was unrated. Rating symbol showed up on the search results.
  2. Went to the site and rated it using the add-on.
  3. Hit the back button and went back to the search results, the rating symbol was missing. Looked at the code and found the undefined.png in the URL.

After I restarted the browser, the rating symbol shows up again. Can't get it to disappear. This could have something to do with rating the site.

sorgoz commented 12 years ago

I've reproduced it on chrome 16.

The same steps: search (in google), go, rate, go back.

sorgoz commented 12 years ago

The problem is near the code:

background.js (86):

var result = wot.getlevel(wot.reputationlevels, cached.value[wot.default_component] ? cached.value[wot.default_component].r : -1).name;

when user rate with "trusworthy" app, it affects cached values.

I'll fix it.

samitolvanen commented 12 years ago

Yes, rating affects the cache, but how is the problem in that function? This geticon function only sets the toolbar icon, the one that wot.search.getcss uses is in wot.js.

sorgoz commented 12 years ago

oh, right. stupid me.

sorgoz commented 12 years ago

aha,

the reason is that geticon is called with "r" == undefined.

samitolvanen commented 12 years ago

The path for the data from the background page's cache to the content script is a bit complicated, so I'm not sure at which point the reputation becomes undefined. Considering that the reputation is shown correctly on the rating window, I think the cache itself is probably fine. There's probably something wrong with wot.search.getreputation.

At least it should use wot.default_component instead of 0 on line 302. This doesn't cause the bug though, just something I noticed. Clearly r is set to null somewhere there...

sorgoz commented 12 years ago

fixed.

samitolvanen commented 12 years ago

Wait a minute. If there's no reputation for a site, there are no elements in the XML response from the query API, right? Does this mean that:

A simple fix would be to either:

samitolvanen commented 12 years ago

Good, that works. We should make sure we don't assume the r attribute exists elsewhere. And also, fix the bug in the Safari and Opera add-ons too.

sorgoz commented 12 years ago

OK, I'll file this issue for other browsers and replace 0 to wot.default_component.

And will check if we assume presence of "r"...

samitolvanen commented 12 years ago

Btw, there's a problem with the fix. If the reputation is zero, it will be considered unknown. Test if the attribute is null instead:

var r = (data[wot.default_component] && data[wot.default_component].r != null) ?
            data[wot_default_component].r : -1;

The same elsewhere in the function too.

sorgoz commented 12 years ago

OK

sorgoz commented 12 years ago

fixed again.