Skip to content

Commit

Permalink
Add net::EscapePath for file_id in DriveApiUrlGenerator.
Browse files Browse the repository at this point in the history
It was a potential issue on url generation for Drive API v2, since the
initial check-in of https://chromiumcodereview.appspot.com/11799003.

BUG=162155
TEST=Ran unit_tests.


Review URL: https://chromiumcodereview.appspot.com/12084064

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@179995 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
hidehiko@chromium.org committed Jan 31, 2013
1 parent 9e0b6d6 commit d8dd0a0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
6 changes: 3 additions & 3 deletions chrome/browser/google_apis/drive_api_url_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "base/string_number_conversions.h"
#include "base/stringprintf.h"
#include "net/base/escape.h"
#include "net/base/url_util.h"

namespace google_apis {
Expand All @@ -17,7 +18,7 @@ const char kDriveV2AboutUrl[] = "/drive/v2/about";
const char kDriveV2ApplistUrl[] = "/drive/v2/apps";
const char kDriveV2ChangelistUrl[] = "/drive/v2/changes";
const char kDriveV2FilelistUrl[] = "/drive/v2/files";
const char kDriveV2FileUrlFormat[] = "/drive/v2/files/%s";
const char kDriveV2FileUrlPrefix[] = "/drive/v2/files/";

} // namespace

Expand Down Expand Up @@ -67,8 +68,7 @@ GURL DriveApiUrlGenerator::GetFilelistUrl(
}

GURL DriveApiUrlGenerator::GetFileUrl(const std::string& file_id) const {
return base_url_.Resolve(
base::StringPrintf(kDriveV2FileUrlFormat, file_id.c_str()));
return base_url_.Resolve(kDriveV2FileUrlPrefix + net::EscapePath(file_id));
}

} // namespace google_apis
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,15 @@ TEST_F(DriveApiUrlGeneratorTest, GetFileUrl) {
url_generator_.GetFileUrl("0ADK06pfg").spec());
EXPECT_EQ("https://www.googleapis.com/drive/v2/files/0Bz0bd074",
url_generator_.GetFileUrl("0Bz0bd074").spec());
EXPECT_EQ("https://www.googleapis.com/drive/v2/files/file%3Afile_id",
url_generator_.GetFileUrl("file:file_id").spec());

EXPECT_EQ("http://127.0.0.1:12345/drive/v2/files/0ADK06pfg",
test_url_generator_.GetFileUrl("0ADK06pfg").spec());
EXPECT_EQ("http://127.0.0.1:12345/drive/v2/files/0Bz0bd074",
test_url_generator_.GetFileUrl("0Bz0bd074").spec());
EXPECT_EQ("http://127.0.0.1:12345/drive/v2/files/file%3Afile_id",
test_url_generator_.GetFileUrl("file:file_id").spec());
}

} // namespace google_apis
9 changes: 4 additions & 5 deletions chrome/browser/google_apis/gdata_wapi_url_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ const char kContentURLFormat[] = "/feeds/default/private/full/%s/contents";
const char kResourceURLForRemovalFormat[] =
"/feeds/default/private/full/%s/contents/%s";

// URL requesting single resource entry whose resource id is specified by "%s".
const char kGetEditURLFormat[] = "/feeds/default/private/full/%s";
// URL requesting single resource entry whose resource id is followed by this
// prefix.
const char kGetEditURLPrefix[] = "/feeds/default/private/full/";

// Root resource list url.
const char kResourceListRootURL[] = "/feeds/default/private/full";
Expand Down Expand Up @@ -154,9 +155,7 @@ GURL GDataWapiUrlGenerator::GenerateEditUrl(

GURL GDataWapiUrlGenerator::GenerateEditUrlWithoutParams(
const std::string& resource_id) const {
return base_url_.Resolve(
base::StringPrintf(kGetEditURLFormat,
net::EscapePath(resource_id).c_str()));
return base_url_.Resolve(kGetEditURLPrefix + net::EscapePath(resource_id));
}

GURL GDataWapiUrlGenerator::GenerateContentUrl(
Expand Down

0 comments on commit d8dd0a0

Please sign in to comment.