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

Side by Side Diff: url/gurl.cc

Issue 2029213002: Fix generation of inner_url in GURL::ReplacementComponents. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Response to comments Created 4 years, 6 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 | « url/gurl.h ('k') | url/gurl_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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "url/gurl.h" 5 #include "url/gurl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <ostream> 10 #include <ostream>
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 // we have room if we have to escape a few things without reallocating. 273 // we have room if we have to escape a few things without reallocating.
274 result.spec_.reserve(spec_.size() + 32); 274 result.spec_.reserve(spec_.size() + 32);
275 url::StdStringCanonOutput output(&result.spec_); 275 url::StdStringCanonOutput output(&result.spec_);
276 276
277 result.is_valid_ = url::ReplaceComponents( 277 result.is_valid_ = url::ReplaceComponents(
278 spec_.data(), static_cast<int>(spec_.length()), parsed_, replacements, 278 spec_.data(), static_cast<int>(spec_.length()), parsed_, replacements,
279 NULL, &output, &result.parsed_); 279 NULL, &output, &result.parsed_);
280 280
281 output.Complete(); 281 output.Complete();
282 if (result.is_valid_ && result.SchemeIsFileSystem()) { 282 if (result.is_valid_ && result.SchemeIsFileSystem()) {
283 result.inner_url_.reset(new GURL(spec_.data(), result.parsed_.Length(), 283 result.inner_url_.reset(new GURL(result.spec_.data(),
284 result.parsed_.Length(),
284 *result.parsed_.inner_parsed(), true)); 285 *result.parsed_.inner_parsed(), true));
285 } 286 }
286 return result; 287 return result;
287 } 288 }
288 289
289 // Note: code duplicated above (it's inconvenient to use a template here). 290 // Note: code duplicated above (it's inconvenient to use a template here).
290 GURL GURL::ReplaceComponents( 291 GURL GURL::ReplaceComponents(
291 const url::Replacements<base::char16>& replacements) const { 292 const url::Replacements<base::char16>& replacements) const {
292 GURL result; 293 GURL result;
293 294
294 // Not allowed for invalid URLs. 295 // Not allowed for invalid URLs.
295 if (!is_valid_) 296 if (!is_valid_)
296 return GURL(); 297 return GURL();
297 298
298 // Reserve enough room in the output for the input, plus some extra so that 299 // Reserve enough room in the output for the input, plus some extra so that
299 // we have room if we have to escape a few things without reallocating. 300 // we have room if we have to escape a few things without reallocating.
300 result.spec_.reserve(spec_.size() + 32); 301 result.spec_.reserve(spec_.size() + 32);
301 url::StdStringCanonOutput output(&result.spec_); 302 url::StdStringCanonOutput output(&result.spec_);
302 303
303 result.is_valid_ = url::ReplaceComponents( 304 result.is_valid_ = url::ReplaceComponents(
304 spec_.data(), static_cast<int>(spec_.length()), parsed_, replacements, 305 spec_.data(), static_cast<int>(spec_.length()), parsed_, replacements,
305 NULL, &output, &result.parsed_); 306 NULL, &output, &result.parsed_);
306 307
307 output.Complete(); 308 output.Complete();
308 if (result.is_valid_ && result.SchemeIsFileSystem()) { 309 if (result.is_valid_ && result.SchemeIsFileSystem()) {
309 result.inner_url_.reset(new GURL(spec_.data(), result.parsed_.Length(), 310 result.inner_url_.reset(new GURL(result.spec_.data(),
311 result.parsed_.Length(),
310 *result.parsed_.inner_parsed(), true)); 312 *result.parsed_.inner_parsed(), true));
311 } 313 }
312 return result; 314 return result;
313 } 315 }
314 316
315 GURL GURL::GetOrigin() const { 317 GURL GURL::GetOrigin() const {
316 // This doesn't make sense for invalid or nonstandard URLs, so return 318 // This doesn't make sense for invalid or nonstandard URLs, so return
317 // the empty URL. 319 // the empty URL.
318 if (!is_valid_ || !IsStandard()) 320 if (!is_valid_ || !IsStandard())
319 return GURL(); 321 return GURL();
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 void GURL::Swap(GURL* other) { 539 void GURL::Swap(GURL* other) {
538 spec_.swap(other->spec_); 540 spec_.swap(other->spec_);
539 std::swap(is_valid_, other->is_valid_); 541 std::swap(is_valid_, other->is_valid_);
540 std::swap(parsed_, other->parsed_); 542 std::swap(parsed_, other->parsed_);
541 inner_url_.swap(other->inner_url_); 543 inner_url_.swap(other->inner_url_);
542 } 544 }
543 545
544 std::ostream& operator<<(std::ostream& out, const GURL& url) { 546 std::ostream& operator<<(std::ostream& out, const GURL& url) {
545 return out << url.possibly_invalid_spec(); 547 return out << url.possibly_invalid_spec();
546 } 548 }
OLDNEW
« no previous file with comments | « url/gurl.h ('k') | url/gurl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698