1

Closed

Non ASCII chraracters in Album Title are not url encoded correctly

description

OAuthUtility.cs has a bug with how characters are encoded in EncodeValue(string value)

If you try and create an album with any extended character it fails with an invalid signature (OAUTH).

Example: "Sample title é" fails.

This code works:

public static string EncodeValue(string value)
    {
        var result = new StringBuilder();
        string acceptedChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~";
        foreach (char symbol in value)
        {
            if (acceptedChars.IndexOf(symbol) != -1)
                result.Append(symbol);
            else
            {
                foreach (byte b in Encoding.UTF8.GetBytes(symbol.ToString()))
                {
                    result.Append('%' + String.Format("{0:X2}", b));
                }
            }
        }
        return result.ToString();
    }
Closed May 27, 2013 at 4:04 AM by alexgh

comments

alexgh wrote May 27, 2013 at 3:37 AM

Great catch!!

It looks like I was only encoding the first character that was non-ascii.

I have a fix along the same lines as your proposed solution!

Thanks,
Alex

wrote May 27, 2013 at 4:04 AM

Resolved with changeset 83826: Fixes a couple of issues reported by users.