Commit dec80a67 authored by arun87.kumar's avatar arun87.kumar Committed by Commit bot

Extraction of the filename from a URL handles the parameters differently now...

Extraction of the filename from a URL handles the parameters differently now by returning the string after the last slash till its following semicolon as FileName.

BUG=323156

Review URL: https://codereview.chromium.org/560283003

Cr-Commit-Position: refs/heads/master@{#299848}
parent c23436ca
......@@ -621,23 +621,13 @@ void DoExtractFileName(const CHAR* spec,
return;
}
// Search backwards for a parameter, which is a normally unused field in a
// URL delimited by a semicolon. We parse the parameter as part of the
// path, but here, we don't want to count it. The last semicolon is the
// parameter. The path should start with a slash, so we don't need to check
// the first one.
// Extract the filename range from the path which is between
// the last slash and the following semicolon.
int file_end = path.end();
for (int i = path.end() - 1; i > path.begin; i--) {
for (int i = path.end() - 1; i >= path.begin; i--) {
if (spec[i] == ';') {
file_end = i;
break;
}
}
// Now search backwards from the filename end to the previous slash
// to find the beginning of the filename.
for (int i = file_end - 1; i >= path.begin; i--) {
if (IsURLSlash(spec[i])) {
} else if (IsURLSlash(spec[i])) {
// File name is everything following this character to the end
*file_name = MakeRange(i + 1, file_end);
return;
......
......@@ -498,8 +498,13 @@ TEST(URLParser, ExtractFileName) {
{"http://www.google.com/foo/bar.html#ref", "bar.html"},
{"http://www.google.com/search/;param", ""},
{"http://www.google.com/foo/bar.html;param#ref", "bar.html"},
{"http://www.google.com/foo/bar.html;foo;param#ref", "bar.html;foo"},
{"http://www.google.com/foo/bar.html;foo;param#ref", "bar.html"},
{"http://www.google.com/foo/bar.html?query#ref", "bar.html"},
{"http://www.google.com/foo;/bar.html", "bar.html"},
{"http://www.google.com/foo;/", ""},
{"http://www.google.com/foo;", "foo"},
{"http://www.google.com/;", ""},
{"http://www.google.com/foo;bar;html", "foo"},
};
for (size_t i = 0; i < arraysize(file_cases); i++) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment