Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7744553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:47:43+00:00 2026-06-01T09:47:43+00:00

I am trying to Percent encode å to %C3%A5 based on RFC 5849 OAuth

  • 0

I am trying to Percent encode å to %C3%A5 based on RFC 5849 OAuth 1.0

http://tools.ietf.org/rfc/rfc5849.txt

This can be seen in the GoCardless Ruby spec
https://github.com/gocardless/gocardless-ruby/blob/master/spec/utils_spec.rb

 it "encodes non-ascii alpha characters" do
    subject["å"].should == "%C3%A5"
 end

My C# code looks like this:

    private const string UnreservedChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.~";

    public static string PercentEncode(string value)
    {
        var input = new StringBuilder();
        foreach (char symbol in value)
        {
            if (UnreservedChars.IndexOf(symbol) != -1)
            {
                input.Append(symbol);
            }
            else
            {
                input.Append('%' + String.Format("{0:X2}", (int)symbol));
            }
        }

        return input.ToString();
    }

These tests are failing:

[Test]
public void It_encodes_non_ascii_alpha_characters()
{
    Util.PercentEncode("å").ShouldBe("%C3%A5"); 
}

Expected string length 6 but was 3. Strings differ at index 1.
  Expected: "%C3%A5"
  But was:  "%E5"
  ------------^

These tests are failing:

[Test]
public void It_encodes_other_non_ascii_characters()
{
    Util.PercentEncode("支払い").ShouldBe("%E6%94%AF%E6%89%95%E3%81%84");
}

Expected string length 27 but was 15. Strings differ at index 1.
 Expected: "%E6%94%AF%E6%89%95%E3%81%84"
 But was:  "%652F%6255%3044"
 ------------^

And BTW I do have passing tests for these:

[Test]
public void It_encodes_reserved_ascii_characters()
{
    Util.PercentEncode(" !\"#$%&'()").ShouldBe("%20%21%22%23%24%25%26%27%28%29");
    Util.PercentEncode("*+,/{|}:;").ShouldBe("%2A%2B%2C%2F%7B%7C%7D%3A%3B");
    Util.PercentEncode("<=>?@[\\]^`").ShouldBe("%3C%3D%3E%3F%40%5B%5C%5D%5E%60");
}

EDIT for anyone wanting to do this here is the working C# code:

public class Util
{
    private const string UnreservedChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.~";

    public static string PercentEncode(string value)
    {
        var input = new StringBuilder();
        foreach (char symbol in value)
        {
            if (UnreservedChars.IndexOf(symbol) != -1)
            {
                input.Append(symbol);
            }
            else
            {
                byte[] bytes = Encoding.UTF8.GetBytes(symbol.ToString());
                foreach (byte b in bytes)
                {
                    input.AppendFormat("%{0:X2}", b);
                }
            }
        }

        return input.ToString();
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T09:47:44+00:00Added an answer on June 1, 2026 at 9:47 am

    The problem is you’re not taking this part into consideration:

    1. Text values are first encoded as UTF-8 octets per [RFC3629] if
      they are not already. This does not include binary values that
      are not intended for human consumption.

    So you should actually use:

    byte[] bytes = Encoding.UTF8.GetBytes(symbol.ToString());
    foreach (byte b in bytes)
    {
        input.AppendFormat("%{0:x2}", b);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to figure out how I can do this properly. The print_r looks like
I'm trying to set the width in percent (80%) of the Facebook code.This doesn't
I am trying to make a SIMPLE Css percent bar. OK go to http://htmledit.squarefree.com/
Trying to make this jQuery filter that uses .find case-insensitive. For example, when the
trying to figure out why this is happening - I have an input text
Possible Duplicate: How to add percent sign to NSString I am trying to print
I'm trying to get the value of the left property (which is in percent)
I'm trying to create an HTML/CSS-based week calendar using CSS display:table-cell styling on the
I'm trying to add an actual percent sign into a printf statement in Java
I'm trying to get charging percent, and exactly the same text that is Windows

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.