Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Space encoding
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  12 messages - Expand all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Rod Begbie  
View profile  
 More options Nov 11 2007, 1:41 am
From: "Rod Begbie" <rodbeg...@gmail.com>
Date: Sun, 11 Nov 2007 01:41:45 -0500
Local: Sun, Nov 11 2007 1:41 am
Subject: Space encoding
I'm seeing a problem in both Twitter's and termie's endpoints, and
want to bring it up.

My JavaScript client is now 95% done, and can now get tokens and
mostly authenticate against servers.

However, I'm getting signature errors when I make calls containing spaces.

For example, this call works:

http://term.ie/oauth/example/echo_api.php?oauth_consumer_key=key&oaut...

However, *this* call doesn't:

http://term.ie/oauth/example/echo_api.php?oauth_consumer_key=key&oaut...

The difference seems to be that I'm calculating the signature
base-string like this:

GET&http%3A%2F%2Fterm.ie%2Foauth%2Fexample%2Fecho_api.php&oauth_consumer_ke y%3Dkey%26oauth_nonce%3D39T1IsTpcA%26oauth_signature_method%3DHMAC-SHA1%26o auth_timestamp%3D1194762831%26oauth_token%3Daccesskey%26oauth_version%3D1.0 %26status%3DHello%20world%21&secret&accesssecret

while Termie's test server (and, I think, Twitter) are expecting this:

GET&http%3A%2F%2Fterm.ie%2Foauth%2Fexample%2Fecho_api.php&oauth_consumer_ke y%3Dkey%26oauth_nonce%3D39T1IsTpcA%26oauth_signature_method%3DHMAC-SHA1%26o auth_timestamp%3D1194762831%26oauth_token%3Daccesskey%26oauth_version%3D1.0 %26status%3DHello+world%21&secret&accesssecret

(Note the space in "Hello world!" has been encoded as a %20 in
JavaScript, but as "+" in the test server base string)

I read the spec as saying that percent-encoding should always be used
(http://oauth.googlecode.com/svn/spec/branches/1.0/drafts/5/spec.html#...).
 Is that right?

Thanks,

Rod.

--
:: Rod Begbie :: http://groovymother.com/ ::


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Eran Hammer-Lahav  
View profile  
 More options Nov 11 2007, 8:39 am
From: Eran Hammer-Lahav <hammerla...@gmail.com>
Date: Sun, 11 Nov 2007 08:39:46 -0500
Local: Sun, Nov 11 2007 8:39 am
Subject: RE: [oauth] Space encoding
Space in parameter name or value must be encoded as %20. The spec doesn't
say how it must be encoded in the URL itself which I guess leaves + as a
valid option. But for the Signature Base String, only %20 can be used. If an
actual + is in the name or value, it must be encoded as %2B.

EHL


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Eran Hammer-Lahav  
View profile  
 More options Nov 11 2007, 8:50 am
From: Eran Hammer-Lahav <hammerla...@gmail.com>
Date: Sun, 11 Nov 2007 08:50:58 -0500
Local: Sun, Nov 11 2007 8:50 am
Subject: RE: [oauth] Space encoding
BTW, because most URL encoding functions are not as restrictive as OAuth, I
use my own functions. It is such a simple process that you might want to
consider just writing your own URL encode. Here are two in C++ and C# that I
use. The nice thing about the C++ one is that it has the double encoded
feature which allows me to write parameters directly into the Signature Base
String instead of using an intermediate string. It saves two copies, one of
the parameters concatenation, and second of the URL encoding of the
normalized string. I just append everything into a stringstream.

EHL

C++:

/*static*/ const std::string    URI::_unreservedChars =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.~";

/*static*/ void
URI::encode(const std::string& value_,
                std::stringstream& stream_,
                const std::string& reserved_ /*= ""*/,
                const bool isDoubleEncoded_ /*= false*/)
{
        for (std::string::const_iterator valueIter = value_.begin();
                valueIter != value_.end();
                ++valueIter)
        {
                char    symbol = *valueIter;
                if (_unreservedChars.find(symbol) != std::string::npos &&
                        reserved_.find(symbol) == std::string::npos)
                {
                        stream_ << symbol;
                }
                else
                {
                        stream_ << char('%');

                        if (isDoubleEncoded_)
                        {
                                stream_ << "25";                // Turn '='
into '%3D' into '%253D'
                        }

                        stream_ <<
Poco::toUpper(Poco::NumberFormatter::formatHex((unsigned)(unsigned char)
symbol, 2));
                }
        }

}

C#:

private static string _unreservedChars =
 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.~";

public static string urlEncode(string value_)
{
    string result = "";

    foreach (char symbol in value_)
    {
        if (_unreservedChars.IndexOf(symbol) != -1)
          {
             result += symbol;
          }
          else
          {
             result += '%' + String.Format("{0:X2}", (int)symbol);
          }
    }

    return result;


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
John Kristian  
View profile  
 More options Nov 12 2007, 10:45 am
From: John Kristian <jkrist...@netflix.com>
Date: Mon, 12 Nov 2007 07:45:41 -0800
Local: Mon, Nov 12 2007 10:45 am
Subject: Re: Space encoding
Note also that OAuth (section 5.4.1) requires the restrictive encoding
for parameters in an Authorization header.  Although it seems like a
good idea for servers to accept any ordinary percent encoding.

    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Eran Hammer-Lahav  
View profile  
 More options Nov 12 2007, 10:56 am
From: Eran Hammer-Lahav <e...@hueniverse.com>
Date: Mon, 12 Nov 2007 10:56:52 -0500
Local: Mon, Nov 12 2007 10:56 am
Subject: RE: [oauth] Re: Space encoding
As long as the Signature Base String uses only the spec's encoding. There is an important difference between using the parameters values and building the Signature Base String. Allowing a looser encoding parsing on the server is ok, as long as when building the SBS the values are re-encoded using the OAuth encoding flavor.

EHL


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Gabe Wachob  
View profile  
 More options Nov 12 2007, 4:32 pm
From: "Gabe Wachob" <gabe.wac...@amsoft.net>
Date: Mon, 12 Nov 2007 13:32:22 -0800
Local: Mon, Nov 12 2007 4:32 pm
Subject: RE: [oauth] Re: Space encoding
Great discussion - could you put up examples of +/%20 encoding on
http://wiki.oauth.net/TestCases ?

This is not the first time the +/%20 encoding issue has come up here or
elsewhere ;-)

    -Gabe


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Blaine Cook  
View profile  
 More options Nov 12 2007, 5:48 pm
From: "Blaine Cook" <rom...@gmail.com>
Date: Mon, 12 Nov 2007 14:48:51 -0800
Local: Mon, Nov 12 2007 5:48 pm
Subject: Re: [oauth] Re: Space encoding

I consider this a bug (in OAuth) - is there a common behaviour that most URL
encoding functions exhibit?

Implementing a URL encode function should *NOT* be part of implementing
OAuth. My implementation currently does:

CGI.escape(value.to_s).gsub("%7E", "~")

but if we stick with the currently more-restrictive encoding, I could do:

CGI.escape(value.to_s).gsub("%7E", "~").gsub("+", "%20")

in Ruby. The question is, do we want to change the encoding to be whatever
the "majority of programming languages do" - the OAuth spec is not the place
to decide that URL encoding has been done wrong in all popular programming
languages. They're simply not going to change for us.

b.

On Nov 11, 2007 5:50 AM, Eran Hammer-Lahav <hammerla...@gmail.com> wrote:


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
John Kristian  
View profile  
 More options Nov 12 2007, 7:07 pm
From: John Kristian <jkrist...@netflix.com>
Date: Mon, 12 Nov 2007 16:07:09 -0800
Local: Mon, Nov 12 2007 7:07 pm
Subject: Re: Space encoding
HTML mandates encoding space as +.
http://www.w3.org/TR/html4/interact/forms.html#h-17.13.4.1

On Nov 12, 2:48 pm, "Blaine Cook" <rom...@gmail.com> wrote:

> ... is there a common behaviour that most URL
> encoding functions exhibit?

In Java, java.net.URLEncoder.encode encodes the characters from space
through tilde as
+%21%22%23%24%25%26%27%28%29*%2B%2C-.%2F0123456789%3A%3B%3C%3D%3E%3F
%40ABCDEFGHIJKLMNOPQRSTUVWXYZ%5B%5C%5D%5E_%60abcdefghijklmnopqrstuvwxyz
%7B%7C%7D%7E

On Nov 12, 1:32 pm, "Gabe Wachob" <gabe.wac...@amsoft.net> wrote:

> Great discussion - could you put up examples of +/%20 encoding on http://wiki.oauth.net/TestCases?

http://wiki.oauth.net/TestCases includes space in two test cases.
Feel free to add more.  (It's a wiki.)

    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Gabe Wachob  
View profile  
 More options Nov 12 2007, 8:02 pm
From: "Gabe Wachob" <gabe.wac...@amsoft.net>
Date: Mon, 12 Nov 2007 17:02:08 -0800
Local: Mon, Nov 12 2007 8:02 pm
Subject: RE: [oauth] Re: Space encoding

This "+" vs. "%20" discussion is a permathread in stds discussions w/r/t
URIs that get placed in various contexts and need to compared with other
URIs or string fragments.

Think may NOT be a bug in OAuth. It is the result of a bug in the state of
the world of specs - because the *unencoding* of ' ' in URIs is handled
differently by different processors - OAuth is simply trying to nail this
ambiguity down. Whether this ambiguity is a problem for OAuth or not is
something I discuss below (I'm leaning towards thinking its *not* a
problem).

The issue arises if you are handed a URI and asked to compare it (or some
part of it) with a string which is NOT encoded (from a URI perspective). For
example, if you have a name that is encoded in a query string - comparing
that name to a name not embedded in a URI may be ambiguous:

http://example.com?Big+Daddy <http://example.com/?Big+Daddy>

Does the query string, unencoded, match "Big Daddy", or "Big+Daddy"? Depends
on which authority you ask (common practice/CGI or RFC 3986).

If you say "Big+Daddy" (RFC 3986)  then

*       I use http://example.com?Big+Daddy <http://example.com/?Big+Daddy>
to encode "Big+Daddy"
*       http://example.com?Big%20Daddy and http://example.com?Big+Daddy
<http://example.com/?Big+Daddy>  are not equivalent
*       You have to make sure out-of-the-box libraries don't treat "+" as an
encoding of ' ', but character-for-character comparison works whether or not
the URI (or subcomponent) is encoded or not.

If you say "Big Daddy" (common pratice/CGI forms), then

*       I have to use http://example.com?Big%2BDaddy to encode "Big+Daddy"
*       Your out-of-the-box libraries will extract the query string as "Big
Daddy" with no special processing
*       By implication 'http://example.com?Big%20Daddy' and
'http://example.com?Big+Daddy' are logically equivalent because the query
string un-encodes to the same thing and the two URIs are the same otherwise.
This also means there are two perfectly equivalent ways of encoding 'Big
Daddy'. We have to confirm/reject that this is an issue for OAuth - this is
the central issue. It really comes down to constructing the signature base
string that gets signed (section 9.1.3) - because there can be no ambiguity
about creating the string that gets signed. That being said, I'm not
actually seeing an issue there right now because the component parts can be
derived from the incoming HTTP request, outside the consumer & token
secrets. *Someone else needs to review this as well though.*  

I hope this directs the analysis.

            -Gabe

  _____  

From: oauth@googlegroups.com [mailto:oauth@googlegroups.com] On Behalf Of
Blaine Cook
Sent: Monday, November 12, 2007 2:49 PM
To: oauth@googlegroups.com
Subject: [oauth] Re: Space encoding

I consider this a bug (in OAuth) - is there a common behaviour that most URL
encoding functions exhibit?

Implementing a URL encode function should *NOT* be part of implementing
OAuth. My implementation currently does:

CGI.escape(value.to_s).gsub("%7E", "~")

but if we stick with the currently more-restrictive encoding, I could do:

CGI.escape(value.to_s).gsub("%7E", "~").gsub("+", "%20")

in Ruby. The question is, do we want to change the encoding to be whatever
the "majority of programming languages do" - the OAuth spec is not the place
to decide that URL encoding has been done wrong in all popular programming
languages. They're simply not going to change for us.

b.

On Nov 11, 2007 5:50 AM, Eran Hammer-Lahav <hammerla...@gmail.com

<mailto:hammerla...@gmail.com> > wrote:

BTW, because most URL encoding functions are not as restrictive as OAuth, I
use my own functions. It is such a simple process that you might want to
consider just writing your own URL encode. Here are two in C++ and C# that I

use. The nice thing about the C++ one is that it has the double encoded
feature which allows me to write parameters directly into the Signature Base
String instead of using an intermediate string. It saves two copies, one of
the parameters concatenation, and second of the URL encoding of the
normalized string. I just append everything into a stringstream.

EHL

C++:

/*static*/ const std::string    URI::_unreservedChars =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.~";

/*static*/ void
URI::encode(const std::string& value_,
               std::stringstream& stream_,
               const std::string& reserved_ /*= ""*/,
               const bool isDoubleEncoded_ /*= false*/)
{
       for (std::string::const_iterator valueIter = value_.begin();
               valueIter != value_.end();
               ++valueIter)
       {
               char    symbol = *valueIter;
               if (_unreservedChars.find(symbol) != std::string::npos &&
                       reserved_.find(symbol) == std::string::npos)
               {
                       stream_ << symbol;
               }
               else
               {
                       stream_ << char('%');

                       if (isDoubleEncoded_)
                       {
                               stream_ << "25";                // Turn '='
into '%3D' into '%253D'
                       }

                       stream_ <<
Poco::toUpper(Poco::NumberFormatter::formatHex((unsigned)(unsigned char)
symbol, 2));
               }
       }

}

C#:

private static string _unreservedChars =
 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.~";

public static string urlEncode(string value_)
{
   string result = "";

   foreach (char symbol in value_)
   {
       if (_unreservedChars.IndexOf(symbol) != -1)
         {
            result += symbol;
         }
         else
         {
            result += '%' + String.Format("{0:X2}", (int)symbol);
         }
   }

   return result;

}

<br

    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Eran Hammer-Lahav  
View profile  
 More options Nov 12 2007, 9:34 pm
From: Eran Hammer-Lahav <e...@hueniverse.com>
Date: Mon, 12 Nov 2007 21:34:30 -0500
Local: Mon, Nov 12 2007 9:34 pm
Subject: RE: [oauth] Re: Space encoding

No no no.

URL encoding and normalization are a problem in general. There is no standard for doing either in a consistent way (i.e. that will always produce identical strings).

I agreed with this argument when we had a problem with base64 implementations. In that case, there is a valid point in not requiring everyone to do base64 on their own and use the tools available. But in the base64 case, it had no impact on the SBS, all RFCs require that the server be able to read any line length (basically ignore all non base64 characters), and overall the RFC we used was the general practice.

With URL encoding, as my code sample shows, it is super easy, and most importantly, consistent and clear. Your own example shows just how simple it is for you to "fix" Ruby's implementation.

EHL

From: oauth@googlegroups.com [mailto:oauth@googlegroups.com] On Behalf Of Blaine Cook
Sent: Monday, November 12, 2007 5:49 PM
To: oauth@googlegroups.com
Subject: [oauth] Re: Space encoding

I consider this a bug (in OAuth) - is there a common behaviour that most URL encoding functions exhibit?

Implementing a URL encode function should *NOT* be part of implementing OAuth. My implementation currently does:

CGI.escape(value.to_s).gsub("%7E", "~")

but if we stick with the currently more-restrictive encoding, I could do:

CGI.escape(value.to_s).gsub("%7E", "~").gsub("+", "%20")

in Ruby. The question is, do we want to change the encoding to be whatever the "majority of programming languages do" - the OAuth spec is not the place to decide that URL encoding has been done wrong in all popular programming languages. They're simply not going to change for us.

b.
On Nov 11, 2007 5:50 AM, Eran Hammer-Lahav <hammerla...@gmail.com <mailto:hammerla...@gmail.com> > wrote:

BTW, because most URL encoding functions are not as restrictive as OAuth, I
use my own functions. It is such a simple process that you might want to
consider just writing your own URL encode. Here are two in C++ and C# that I
use. The nice thing about the C++ one is that it has the double encoded
feature which allows me to write parameters directly into the Signature Base
String instead of using an intermediate string. It saves two copies, one of
the parameters concatenation, and second of the URL encoding of the
normalized string. I just append everything into a stringstream.

EHL

C++:

/*static*/ const std::string    URI::_unreservedChars =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.~";

/*static*/ void
URI::encode(const std::string& value_,
               std::stringstream& stream_,
               const std::string& reserved_ /*= ""*/,
               const bool isDoubleEncoded_ /*= false*/)
{
       for (std::string::const_iterator valueIter = value_.begin();
               valueIter != value_.end();
               ++valueIter)
       {
               char    symbol = *valueIter;
               if (_unreservedChars.find(symbol) != std::string::npos &&
                       reserved_.find(symbol) == std::string::npos)
               {
                       stream_ << symbol;
               }
               else
               {
                       stream_ << char('%');

                       if (isDoubleEncoded_)
                       {
                               stream_ << "25";                // Turn '='
into '%3D' into '%253D'
                       }

                       stream_ <<
Poco::toUpper(Poco::NumberFormatter::formatHex((unsigned)(unsigned char)
symbol, 2));
               }
       }

}

C#:

private static string _unreservedChars =
 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.~";

public static string urlEncode(string value_)
{
   string result = "";

   foreach (char symbol in value_)
   {
       if (_unreservedChars.IndexOf(symbol) != -1)
         {
            result += symbol;
         }
         else
         {
            result += '%' + String.Format("{0:X2}", (int)symbol);
         }
   }

   return result;

}

<br

    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Blaine Cook  
View profile  
 More options Nov 12 2007, 10:02 pm
From: Blaine Cook <rom...@gmail.com>
Date: Mon, 12 Nov 2007 19:02:07 -0800
Local: Mon, Nov 12 2007 10:02 pm
Subject: Re: [oauth] Re: Space encoding

... As long as the only differences are the space and ~

Gabe's arguments are probably the most compelling here. The spec as-is  
is fine.

b.

On Nov 12, 2007, at 18:34, Eran Hammer-Lahav <e...@hueniverse.com>  
wrote:


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
John Kristian  
View profile  
 More options Nov 13 2007, 11:22 am
From: John Kristian <jkrist...@netflix.com>
Date: Tue, 13 Nov 2007 08:22:49 -0800
Local: Tues, Nov 13 2007 11:22 am
Subject: Re: Space encoding
It's not hard to implement the OAuth encoding in Java:
URLEncoder.encode(s, "UTF-8")
    .replace("+", "%20").replace("*", "%2A").replace("%7E", "~")

More efficient implementations are possible.

On Nov 12, 6:34 pm, Eran Hammer-Lahav <e...@hueniverse.com> wrote:


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2010 Google