Wavatars: Debugging

By Shamus
on Mar 24, 2008
Filed under:
Projects

Okay, about a dozen people have emailed me over the last few months to tell me my code is wrong. Which is true. The line in question is where I make the URL for the gravatar.

I do it thus:

gravatar_id=$md5.jpg&;r=$rating&;s=$size&;d=$url

The important thing being that the fields have an ampersand, followed by a semicolon. The API calls for just an ampersand. So my code is “wrong”, except that it works. If I use “correct” code:

gravatar_id=$md5.jpg&rating=$rating&size=$size&d=$url

It breaks. Wavatars show up, but Gravatars do not. Everyone shows up as a wavatar.

Other people report the opposite: My code breaks, the correct code works as it should. It’s pissing me off, because I don’t have the time or the patience to sort out this nonsense, which (I’m guessing) comes from differing versions of PHP. To really fix the problem, I have to figure out what PHP options or versions are causing the different behavior, check for them, and use the different versions of the URL based on those values. I could sink a lot of hours into a fishing expedition like that, and I just don’t have them right now.

Having said that, if anyone has a guess, please drop a comment.

LATER: Perhaps it’s not related to PHP versions. I found a case where leaving the “ratings” blank would cause my code to work, and filling it in would cause the correct code to work.

Enjoyed this post? Please share!


11Just 11 comments.

From the Archives:

  1. Tuck says:

    Whoops, I added a comment to the wrong post. Added again below for extra spamminess:

    gravatar_id=$md5.jpg&rating=$rating&size=$size&d=$url

    You’ll have to put an extra semicolon (;) after each & in the above quoted “correct” code.

    Otherwise you’ll lose the semicolons as they’re part of the code for the ampersand.

    Try this?

    gravatar_id=$md5.jpg&;rating=$rating&;size=$size&;d=$url

    Disclaimer: I know nothing about gravatars, wavatars, wordpress or blogging.

    EDIT: And the suggestion I made lost the important bits when I posted it…should be correct this time…I think.

  2. How come in the first code snippet, the ampersands are showing as a single ampersand, and in the second, they are showing as XML-encoded ampersands? This may be related to your problem, or it may be entirely a display artifact. (Which is why I described the results in English instead of trying to type them; comment engines often have the same trouble.)

    That is, in one snippet it’s x=1&y=2, and the other it’s x=1&y=2 . As literally appearing in HTML, it probably should be x=1&y=2. (And while the comments are displaying what I submit correctly, it’s leaking escaping levels when I edit the comment: & gets collapsed to &.)

    As of this posting, you’re outputting “&;” which won’t work at all.

  3. Sord says:

    I did a few quick tests, and it looks like it is the rating field that may be giving you problems. If the rating field has an invalid rating value, the gravatar site will always go to the default. Right now your site is attempting to pass a blank rating (which is not a valid rating), so the result should be only wavatars show up.

    However, the extra semi-colon in your broken version doesn’t send “rating”, it sends “;rating” which the gravatar site ignores. So that allows the gravatars to show up correctly, but since you also send “;default” the default value is also being ignored, so you do not get any wavatars.

    My suggestion is to use the correct & and make sure you either fill in a valid rating or leave the rating field off.

    Note that it is the browser that converts the & code to a single & so a correct url will just have the & in it. It is possible that some browsers treat the &; pattern as special (in an attempt to clean up poorly written html pages) and that may be resulting in inconsistent behavior across browsers.

  4. Miral says:

    I’m with Sord. You should always use the proper & (and not some evil corruption like &; or &;).

    But the $rating you’re currently passing in is blank. So if you fix the code and then go to your wavatar options page in the dashboard and type in “PG” then it should start working properly again.

    (I think one of the issues here is that with the current code the rating field defaults to blank, not to a valid rating. That probably ought to get fixed too.)

    Also, as I specified in the patch you should technically be calling urlencode rather than passing the default URL in directly. The old gravatar site didn’t care since the URL you’re using didn’t contain any ampersands, but since it does contain slashes it is permitted for it to be parsed in a way that will produce a completely different result from what you want. I’m not sure if that’s actually the case (I’ve never tried not using urlencode, since I know it’s the right thing to do), so you might still be able to get away with not doing it. But you ought to :)

  5. Miral says:

    Yay, they’re alive again :D

  6. xbolt says:

    They… Live… Again! :D

  7. Aaron says:

    This is one of those situations where I have absolutely no knowledge of the specialty at hand, but I’m very glad many of you do.

    At the risk of sounding like a bad Roddy Piper 80’s movie: They Live!!

  8. Martin says:

    My mischievous caltrop guy is back

  9. siliconscout says:

    meh…. this is why I love (and hate) coding

    edit: I notice the captcha is gone now is that intentional?

  10. Kanthalion says:

    It’s been gone for a while, Siliconscout. If you look down on the bottom of the page there is a button listing how many spam comments he has had that will explain it all.

  11. LeFarr says:

    Gotta say, I love this Wavatar thing. It will stop the whole “My avatar’s better” war that occurs on some blogs.

Leave a Reply

Comments are moderated and may not be posted immediately. Required fields are marked *

*
*

Thanks for joining the discussion. Be nice, don't post angry, and enjoy yourself. This is supposed to be fun.

You can enclose spoilers in <strike> tags like so:
<strike>Darth Vader is Luke's father!</strike>

You can make things italics like this:
Can you imagine having Darth Vader as your <i>father</i>?

You can make things bold like this:
I'm <b>very</b> glad Darth Vader isn't my father.

You can make links like this:
I'm reading about <a href="http://en.wikipedia.org/wiki/Darth_Vader">Darth Vader</a> on Wikipedia!

You can quote someone like this:
Darth Vader said <blockquote>Luke, I am your father.</blockquote>