ip2k / google-api-ruby-client

Automatically exported from code.google.com/p/google-api-ruby-client
Apache License 2.0
0 stars 0 forks source link

URL escaping parameters #14

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
You can't pass URL-escaped parameters to Google::APIClient#execute because it 
will URL-escape the '%'. If you don't pass URL-escaped parameters, the method 
won't escape them.

Here's some rails console code that illustrates the issue:

calendar_api = ::Google::APIClient::API.new(
  "https://www.google.com",
  { "basePath" => "/calendar/feeds/",
    "resources" => {
      "calendarlists" => {
        "methods" => {
          "ownedlist" => {
            "id" => "calendars.calendarlists.ownedlist",
            "path" => "default/owncalendars/full",
            "httpMethod" => "GET"
          }
        }
      },
      "events" => {
        "methods" => {
          "list" => {
            "id" => "calendars.events.list",
            "path" => "{calendar_id}/private/full",
            "httpMethod" => "GET",
            "parameters" => {
              "calendar_id" => {
                "type" => "string",
                "required" => true,
                "location" => "path"
              }
            }
          }
        }
      } 
    }
  }
)

# Using URL-escaped parameters

params = { "calendar_id" => "1", "start-min"=>"2011-07-28T16%3A00%3A00Z" }

calendar_api.events.list.generate_request(params,'',[])
 => ["GET", "https://www.google.com/calendar/feeds/1/private/full?alt=jsonc&start-min=2011-07-28T16%253A00%253A00Z", [], [""]]

# Not using URL-escaped parameters

params = { "calendar_id" => "1", "start-min"=>"2011-07-29T02:58:21+08:00" }

calendar_api.events.list.generate_request(params,'',[])
 => ["GET", "https://www.google.com/calendar/feeds/4/private/full?alt=jsonc&start-min=2011-07-29T02:58:21+08:00", [], [""]]

# Notice that the ':' and '+' characters are not URL-encoded

I'm using google-api-ruby-client version 0.2.0 with ruby 1.9.2p180 (2011-02-18 
revision 30909. I see this problem on Mac OS 10.6.7 and Ubuntu 10.4 

Original issue reported on code.google.com by dking1...@gmail.com on 28 Jul 2011 at 11:19

GoogleCodeExporter commented 9 years ago
They're not encoded because they're not required to be by RFC 3986. The normal 
form for these characters when appearing in a query string is unencoded.

If the API requires this, that's a bug in the API and you should report this to 
the Calendar team.

Original comment by bobaman@google.com on 1 Aug 2011 at 4:51

GoogleCodeExporter commented 9 years ago
Just as a clarification so that you can check this for yourself, the `pchar` 
rule explicitly includes the ':' character and `sub-delim`s, and the 
`sub-delims` rule includes the '+' character. A query is zero or more `pchar`, 
'/', or '?' characters.

Original comment by bobaman@google.com on 1 Aug 2011 at 4:56

GoogleCodeExporter commented 9 years ago
You are correct. The '+' in the query does not need to be percent-encoded to 
comply with RFC 3986. I'll report this issue to the Calendar API team.

It would be helpful if the Google Client API accepted percent-encoded 
parameters so users could work around these types of problems.

In the Google Data Protocol reference 
(http://code.google.com/apis/gdata/docs/2.0/reference.html), it expects all 
parameters to be URL encoded:

> The standard query parameters are summarized in the following table. All 
parameter values need to be URL encoded.

Thanks for the great library.

Original comment by dking1...@gmail.com on 1 Aug 2011 at 5:55

GoogleCodeExporter commented 9 years ago
We've made a tentative change to the execute method that would allow you to 
supply a raw URI instead of API method and parameters, but it may or may not 
survive in its current form to the next stable release, but in any case, I 
intend to provide a mechanism to make a request for a raw URI in lieu of API 
method and parameters.

The thought is that incorrect or unsupported behavior should be possible when 
absolutely necessary for some reason, but never easy.

Original comment by bobaman@google.com on 1 Aug 2011 at 6:08

GoogleCodeExporter commented 9 years ago
Also just to be clear, the parameters *are* being percent encoded. It's just 
that neither ':' or '+' are among the characters that are supposed to be 
encoded.

Original comment by bobaman@google.com on 1 Aug 2011 at 6:10

GoogleCodeExporter commented 9 years ago
Anyway, hope that helps. Could you update this bug when the Calendar team 
responds, just in case someone searches for this later?

Thanks.

Original comment by bobaman@google.com on 1 Aug 2011 at 6:12

GoogleCodeExporter commented 9 years ago
I created issue #2673 with the Google Data API project:
  http://code.google.com/p/gdata-issues/issues/detail?id=2673

Original comment by dking1...@gmail.com on 1 Aug 2011 at 6:22