OLD | NEW |
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 // Canonicalizer functions for working with and resolving relative URLs. | 5 // Canonicalizer functions for working with and resolving relative URLs. |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "url/url_canon.h" | 8 #include "url/url_canon.h" |
9 #include "url/url_canon_internal.h" | 9 #include "url/url_canon_internal.h" |
10 #include "url/url_constants.h" | 10 #include "url/url_constants.h" |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 } | 163 } |
164 | 164 |
165 // Two or more slashes after the scheme we treat as absolute. | 165 // Two or more slashes after the scheme we treat as absolute. |
166 return true; | 166 return true; |
167 } | 167 } |
168 | 168 |
169 // Copies all characters in the range [begin, end) of |spec| to the output, | 169 // Copies all characters in the range [begin, end) of |spec| to the output, |
170 // up until and including the last slash. There should be a slash in the | 170 // up until and including the last slash. There should be a slash in the |
171 // range, if not, nothing will be copied. | 171 // range, if not, nothing will be copied. |
172 // | 172 // |
173 // The input is assumed to be canonical, so we search only for exact slashes | 173 // For stardard URLs the input should be canonical, but when resolving relative |
174 // and not backslashes as well. We also know that it's ASCII. | 174 // URLs on a non-standard base (like "data:") the input can be anything. |
175 void CopyToLastSlash(const char* spec, | 175 void CopyToLastSlash(const char* spec, |
176 int begin, | 176 int begin, |
177 int end, | 177 int end, |
178 CanonOutput* output) { | 178 CanonOutput* output) { |
179 // Find the last slash. | 179 // Find the last slash. |
180 int last_slash = -1; | 180 int last_slash = -1; |
181 for (int i = end - 1; i >= begin; i--) { | 181 for (int i = end - 1; i >= begin; i--) { |
182 if (spec[i] == '/') { | 182 if (spec[i] == '/' || spec[i] == '\\') { |
183 last_slash = i; | 183 last_slash = i; |
184 break; | 184 break; |
185 } | 185 } |
186 } | 186 } |
187 if (last_slash < 0) | 187 if (last_slash < 0) |
188 return; // No slash. | 188 return; // No slash. |
189 | 189 |
190 // Copy. | 190 // Copy. |
191 for (int i = begin; i <= last_slash; i++) | 191 for (int i = begin; i <= last_slash; i++) |
192 output->push_back(spec[i]); | 192 output->push_back(spec[i]); |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 const Component& relative_component, | 551 const Component& relative_component, |
552 CharsetConverter* query_converter, | 552 CharsetConverter* query_converter, |
553 CanonOutput* output, | 553 CanonOutput* output, |
554 Parsed* out_parsed) { | 554 Parsed* out_parsed) { |
555 return DoResolveRelativeURL<base::char16>( | 555 return DoResolveRelativeURL<base::char16>( |
556 base_url, base_parsed, base_is_file, relative_url, | 556 base_url, base_parsed, base_is_file, relative_url, |
557 relative_component, query_converter, output, out_parsed); | 557 relative_component, query_converter, output, out_parsed); |
558 } | 558 } |
559 | 559 |
560 } // namespace url | 560 } // namespace url |
OLD | NEW |