summaryrefslogtreecommitdiffstats
path: root/url/url_parse_file.cc
diff options
context:
space:
mode:
authortsepez@chromium.org <tsepez@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-18 22:55:31 +0000
committertsepez@chromium.org <tsepez@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-18 22:55:31 +0000
commit598c8382c9e0556f16a486d758c61d108b4732e0 (patch)
treec3133ca8061e4eee70d10060d84fb1f04bd6621c /url/url_parse_file.cc
parentb887a2620262a8b51be8973cbd366e03e5ddaed9 (diff)
downloadchromium_src-598c8382c9e0556f16a486d758c61d108b4732e0.zip
chromium_src-598c8382c9e0556f16a486d758c61d108b4732e0.tar.gz
chromium_src-598c8382c9e0556f16a486d758c61d108b4732e0.tar.bz2
Make relative file url parsing fail where there is a host:port in the relative URL.
BUG=285720 R=brettw@chromium.org, jar@chromium.org Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=223928 Review URL: https://codereview.chromium.org/23464046 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@223969 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'url/url_parse_file.cc')
-rw-r--r--url/url_parse_file.cc18
1 files changed, 11 insertions, 7 deletions
diff --git a/url/url_parse_file.cc b/url/url_parse_file.cc
index a8907e7..a2f7ce3 100644
--- a/url/url_parse_file.cc
+++ b/url/url_parse_file.cc
@@ -110,8 +110,9 @@ void DoParseLocalFile(const CHAR* spec,
}
// Backend for the external functions that operates on either char type.
-// We are handed the character after the "file:" at the beginning of the spec.
-// Usually this is a slash, but needn't be; we allow paths like "file:c:\foo".
+// Handles cases where there is a scheme, but also when handed the first
+// character following the "file:" at the beginning of the spec. If so,
+// this is usually a slash, but needn't be; we allow paths like "file:c:\foo".
template<typename CHAR>
void DoParseFileURL(const CHAR* spec, int spec_len, Parsed* parsed) {
DCHECK(spec_len >= 0);
@@ -130,8 +131,8 @@ void DoParseFileURL(const CHAR* spec, int spec_len, Parsed* parsed) {
int begin = 0;
TrimURL(spec, &begin, &spec_len);
- // Find the scheme.
- int num_slashes;
+ // Find the scheme, if any.
+ int num_slashes = CountConsecutiveSlashes(spec, begin, spec_len);
int after_scheme;
int after_slashes;
#ifdef WIN32
@@ -140,7 +141,6 @@ void DoParseFileURL(const CHAR* spec, int spec_len, Parsed* parsed) {
// links like "c:/foo/bar" or "//foo/bar". This is also called by the
// relative URL resolver when it determines there is an absolute URL, which
// may give us input like "/c:/foo".
- num_slashes = CountConsecutiveSlashes(spec, begin, spec_len);
after_slashes = begin + num_slashes;
if (DoesBeginWindowsDriveSpec(spec, after_slashes, spec_len)) {
// Windows path, don't try to extract the scheme (for example, "c:\foo").
@@ -153,7 +153,12 @@ void DoParseFileURL(const CHAR* spec, int spec_len, Parsed* parsed) {
} else
#endif
{
- if (ExtractScheme(&spec[begin], spec_len - begin, &parsed->scheme)) {
+ // ExtractScheme doesn't understand the possibility of filenames with
+ // colons in them, in which case it returns the entire spec up to the
+ // colon as the scheme. So handle /foo.c:5 as a file but foo.c:5 as
+ // the foo.c: scheme.
+ if (!num_slashes &&
+ ExtractScheme(&spec[begin], spec_len - begin, &parsed->scheme)) {
// Offset the results since we gave ExtractScheme a substring.
parsed->scheme.begin += begin;
after_scheme = parsed->scheme.end() + 1;
@@ -173,7 +178,6 @@ void DoParseFileURL(const CHAR* spec, int spec_len, Parsed* parsed) {
}
num_slashes = CountConsecutiveSlashes(spec, after_scheme, spec_len);
-
after_slashes = after_scheme + num_slashes;
#ifdef WIN32
// Check whether the input is a drive again. We checked above for windows