Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(464)

Side by Side Diff: url/third_party/mozilla/url_parse.cc

Issue 560283003: Wrong filename on file upload (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added unit testcases and modified code accordingly Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | url/url_parse_unittest.cc » ('j') | url/url_parse_unittest.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* Based on nsURLParsers.cc from Mozilla 1 /* Based on nsURLParsers.cc from Mozilla
2 * ------------------------------------- 2 * -------------------------------------
3 * The contents of this file are subject to the Mozilla Public License Version 3 * The contents of this file are subject to the Mozilla Public License Version
4 * 1.1 (the "License"); you may not use this file except in compliance with 4 * 1.1 (the "License"); you may not use this file except in compliance with
5 * the License. You may obtain a copy of the License at 5 * the License. You may obtain a copy of the License at
6 * http://www.mozilla.org/MPL/ 6 * http://www.mozilla.org/MPL/
7 * 7 *
8 * Software distributed under the License is distributed on an "AS IS" basis, 8 * Software distributed under the License is distributed on an "AS IS" basis,
9 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 9 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
10 * for the specific language governing rights and limitations under the 10 * for the specific language governing rights and limitations under the
(...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 if (!path.is_nonempty()) { 619 if (!path.is_nonempty()) {
620 file_name->reset(); 620 file_name->reset();
621 return; 621 return;
622 } 622 }
623 623
624 // Search backwards for a parameter, which is a normally unused field in a 624 // Search backwards for a parameter, which is a normally unused field in a
625 // URL delimited by a semicolon. We parse the parameter as part of the 625 // URL delimited by a semicolon. We parse the parameter as part of the
626 // path, but here, we don't want to count it. The last semicolon is the 626 // path, but here, we don't want to count it. The last semicolon is the
627 // parameter. The path should start with a slash, so we don't need to check 627 // parameter. The path should start with a slash, so we don't need to check
628 // the first one. 628 // the first one.
629 bool is_file_end_fixed = false;
629 int file_end = path.end(); 630 int file_end = path.end();
630 for (int i = path.end() - 1; i > path.begin; i--) { 631 for (int i = path.end() - 1; i >= path.begin; i--) {
631 if (spec[i] == ';') { 632 if (!is_file_end_fixed && spec[i] == ';') {
brettw 2014/09/16 22:37:10 It seems that this behavior takes everything betwe
arun87.kumar 2014/09/17 11:39:12 i too felt that incase of "foo/bar;baz;lala", the
632 file_end = i; 633 file_end = i;
633 break; 634 is_file_end_fixed = true;
634 } 635 }else if (IsURLSlash(spec[i])) {
brettw 2014/09/16 22:37:10 Space before "else"
arun87.kumar 2014/09/17 11:39:12 Done.
635 } 636 // search backwards from the filename end to the previous slash
brettw 2014/09/16 22:37:09 This comment should be updated (this code no longe
arun87.kumar 2014/09/17 11:39:12 Done.
636 637 // to find the beginning of the filename.
637 // Now search backwards from the filename end to the previous slash
638 // to find the beginning of the filename.
639 for (int i = file_end - 1; i >= path.begin; i--) {
640 if (IsURLSlash(spec[i])) {
641 // File name is everything following this character to the end 638 // File name is everything following this character to the end
642 *file_name = MakeRange(i + 1, file_end); 639 *file_name = MakeRange(i + 1, file_end);
643 return; 640 return;
644 } 641 }
645 } 642 }
646 643
brettw 2014/09/16 22:37:09 Watch out for extra spaces.
arun87.kumar 2014/09/17 11:39:12 Done.
647 // No slash found, this means the input was degenerate (generally paths 644 // No slash found, this means the input was degenerate (generally paths
648 // will start with a slash). Let's call everything the file name. 645 // will start with a slash). Let's call everything the file name.
649 *file_name = MakeRange(path.begin, file_end); 646 *file_name = MakeRange(path.begin, file_end);
650 return; 647 return;
651 } 648 }
652 649
653 template<typename CHAR> 650 template<typename CHAR>
654 bool DoExtractQueryKeyValue(const CHAR* spec, 651 bool DoExtractQueryKeyValue(const CHAR* spec,
655 Component* query, 652 Component* query,
656 Component* key, 653 Component* key,
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
935 } 932 }
936 933
937 void ParseAfterScheme(const base::char16* spec, 934 void ParseAfterScheme(const base::char16* spec,
938 int spec_len, 935 int spec_len,
939 int after_scheme, 936 int after_scheme,
940 Parsed* parsed) { 937 Parsed* parsed) {
941 DoParseAfterScheme(spec, spec_len, after_scheme, parsed); 938 DoParseAfterScheme(spec, spec_len, after_scheme, parsed);
942 } 939 }
943 940
944 } // namespace url 941 } // namespace url
OLDNEW
« no previous file with comments | « no previous file | url/url_parse_unittest.cc » ('j') | url/url_parse_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698