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

Side by Side Diff: src/url_canon_path.cc

Issue 10386035: Fix path component length for zero-length paths canonicalized to '/'. (Closed) Base URL: http://google-url.googlecode.com/svn/trunk/
Patch Set: Created 8 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | src/url_canon_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2007, Google Inc. 1 // Copyright 2007, Google Inc.
2 // All rights reserved. 2 // All rights reserved.
3 // 3 //
4 // Redistribution and use in source and binary forms, with or without 4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are 5 // modification, are permitted provided that the following conditions are
6 // met: 6 // met:
7 // 7 //
8 // * Redistributions of source code must retain the above copyright 8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer. 9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above 10 // * Redistributions in binary form must reproduce the above
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 } 318 }
319 return success; 319 return success;
320 } 320 }
321 321
322 template<typename CHAR, typename UCHAR> 322 template<typename CHAR, typename UCHAR>
323 bool DoPath(const CHAR* spec, 323 bool DoPath(const CHAR* spec,
324 const url_parse::Component& path, 324 const url_parse::Component& path,
325 CanonOutput* output, 325 CanonOutput* output,
326 url_parse::Component* out_path) { 326 url_parse::Component* out_path) {
327 bool success = true; 327 bool success = true;
328 out_path->begin = output->length();
328 if (path.len > 0) { 329 if (path.len > 0) {
329 out_path->begin = output->length();
330
331 // Write out an initial slash if the input has none. If we just parse a URL 330 // Write out an initial slash if the input has none. If we just parse a URL
332 // and then canonicalize it, it will of course have a slash already. This 331 // and then canonicalize it, it will of course have a slash already. This
333 // check is for the replacement and relative URL resolving cases of file 332 // check is for the replacement and relative URL resolving cases of file
334 // URLs. 333 // URLs.
335 if (!url_parse::IsURLSlash(spec[path.begin])) 334 if (!url_parse::IsURLSlash(spec[path.begin]))
336 output->push_back('/'); 335 output->push_back('/');
337 336
338 success = DoPartialPath<CHAR, UCHAR>(spec, path, out_path->begin, output); 337 success = DoPartialPath<CHAR, UCHAR>(spec, path, out_path->begin, output);
339 out_path->len = output->length() - out_path->begin;
340 } else { 338 } else {
341 // No input, canonical path is a slash. 339 // No input, canonical path is a slash.
342 output->push_back('/'); 340 output->push_back('/');
343 *out_path = url_parse::Component();
344 } 341 }
342 out_path->len = output->length() - out_path->begin;
345 return success; 343 return success;
346 } 344 }
347 345
348 } // namespace 346 } // namespace
349 347
350 bool CanonicalizePath(const char* spec, 348 bool CanonicalizePath(const char* spec,
351 const url_parse::Component& path, 349 const url_parse::Component& path,
352 CanonOutput* output, 350 CanonOutput* output,
353 url_parse::Component* out_path) { 351 url_parse::Component* out_path) {
354 return DoPath<char, unsigned char>(spec, path, output, out_path); 352 return DoPath<char, unsigned char>(spec, path, output, out_path);
(...skipping 16 matching lines...) Expand all
371 369
372 bool CanonicalizePartialPath(const char16* spec, 370 bool CanonicalizePartialPath(const char16* spec,
373 const url_parse::Component& path, 371 const url_parse::Component& path,
374 int path_begin_in_output, 372 int path_begin_in_output,
375 CanonOutput* output) { 373 CanonOutput* output) {
376 return DoPartialPath<char16, char16>(spec, path, path_begin_in_output, 374 return DoPartialPath<char16, char16>(spec, path, path_begin_in_output,
377 output); 375 output);
378 } 376 }
379 377
380 } // namespace url_canon 378 } // namespace url_canon
OLDNEW
« no previous file with comments | « no previous file | src/url_canon_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698