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 #include "url/url_util.h" | 5 #include "url/url_util.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <string.h> | 8 #include <string.h> |
9 | 9 |
10 #include "base/debug/leak_annotations.h" | 10 #include "base/debug/leak_annotations.h" |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 | 178 |
179 template<typename CHAR> | 179 template<typename CHAR> |
180 bool DoFindAndCompareScheme(const CHAR* str, | 180 bool DoFindAndCompareScheme(const CHAR* str, |
181 int str_len, | 181 int str_len, |
182 const char* compare, | 182 const char* compare, |
183 Component* found_scheme) { | 183 Component* found_scheme) { |
184 // Before extracting scheme, canonicalize the URL to remove any whitespace. | 184 // Before extracting scheme, canonicalize the URL to remove any whitespace. |
185 // This matches the canonicalization done in DoCanonicalize function. | 185 // This matches the canonicalization done in DoCanonicalize function. |
186 RawCanonOutputT<CHAR> whitespace_buffer; | 186 RawCanonOutputT<CHAR> whitespace_buffer; |
187 int spec_len; | 187 int spec_len; |
188 const CHAR* spec = RemoveURLWhitespace(str, str_len, | 188 const CHAR* spec = |
189 &whitespace_buffer, &spec_len); | 189 RemoveURLWhitespace(str, str_len, &whitespace_buffer, &spec_len, nullptr); |
190 | 190 |
191 Component our_scheme; | 191 Component our_scheme; |
192 if (!ExtractScheme(spec, spec_len, &our_scheme)) { | 192 if (!ExtractScheme(spec, spec_len, &our_scheme)) { |
193 // No scheme. | 193 // No scheme. |
194 if (found_scheme) | 194 if (found_scheme) |
195 *found_scheme = Component(); | 195 *found_scheme = Component(); |
196 return false; | 196 return false; |
197 } | 197 } |
198 if (found_scheme) | 198 if (found_scheme) |
199 *found_scheme = our_scheme; | 199 *found_scheme = our_scheme; |
200 return DoCompareSchemeComponent(spec, our_scheme, compare); | 200 return DoCompareSchemeComponent(spec, our_scheme, compare); |
201 } | 201 } |
202 | 202 |
203 template <typename CHAR> | 203 template <typename CHAR> |
204 bool DoCanonicalize(const CHAR* spec, | 204 bool DoCanonicalize(const CHAR* spec, |
205 int spec_len, | 205 int spec_len, |
206 bool trim_path_end, | 206 bool trim_path_end, |
207 WhitespaceRemovalPolicy whitespace_policy, | 207 WhitespaceRemovalPolicy whitespace_policy, |
208 CharsetConverter* charset_converter, | 208 CharsetConverter* charset_converter, |
209 CanonOutput* output, | 209 CanonOutput* output, |
210 Parsed* output_parsed) { | 210 Parsed* output_parsed) { |
211 output->ReserveSizeIfNeeded(spec_len); | 211 output->ReserveSizeIfNeeded(spec_len); |
212 | 212 |
213 // Remove any whitespace from the middle of the relative URL if necessary. | 213 // Remove any whitespace from the middle of the relative URL if necessary. |
214 // Possibly this will result in copying to the new buffer. | 214 // Possibly this will result in copying to the new buffer. |
215 RawCanonOutputT<CHAR> whitespace_buffer; | 215 RawCanonOutputT<CHAR> whitespace_buffer; |
216 if (whitespace_policy == REMOVE_WHITESPACE) { | 216 if (whitespace_policy == REMOVE_WHITESPACE) { |
217 int original_len = spec_len; | 217 spec = RemoveURLWhitespace(spec, spec_len, &whitespace_buffer, &spec_len, |
218 spec = | 218 &output_parsed->potentially_dangling_markup); |
219 RemoveURLWhitespace(spec, original_len, &whitespace_buffer, &spec_len); | |
220 if (spec_len != original_len) | |
221 output_parsed->whitespace_removed = true; | |
222 } | 219 } |
223 | 220 |
224 Parsed parsed_input; | 221 Parsed parsed_input; |
225 #ifdef WIN32 | 222 #ifdef WIN32 |
226 // For Windows, we allow things that look like absolute Windows paths to be | 223 // For Windows, we allow things that look like absolute Windows paths to be |
227 // fixed up magically to file URLs. This is done for IE compatibility. For | 224 // fixed up magically to file URLs. This is done for IE compatibility. For |
228 // example, this will change "c:/foo" into a file URL rather than treating | 225 // example, this will change "c:/foo" into a file URL rather than treating |
229 // it as a URL with the protocol "c". It also works for UNC ("\\foo\bar.txt"). | 226 // it as a URL with the protocol "c". It also works for UNC ("\\foo\bar.txt"). |
230 // There is similar logic in url_canon_relative.cc for | 227 // There is similar logic in url_canon_relative.cc for |
231 // | 228 // |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 const Parsed& base_parsed, | 286 const Parsed& base_parsed, |
290 const CHAR* in_relative, | 287 const CHAR* in_relative, |
291 int in_relative_length, | 288 int in_relative_length, |
292 CharsetConverter* charset_converter, | 289 CharsetConverter* charset_converter, |
293 CanonOutput* output, | 290 CanonOutput* output, |
294 Parsed* output_parsed) { | 291 Parsed* output_parsed) { |
295 // Remove any whitespace from the middle of the relative URL, possibly | 292 // Remove any whitespace from the middle of the relative URL, possibly |
296 // copying to the new buffer. | 293 // copying to the new buffer. |
297 RawCanonOutputT<CHAR> whitespace_buffer; | 294 RawCanonOutputT<CHAR> whitespace_buffer; |
298 int relative_length; | 295 int relative_length; |
299 const CHAR* relative = RemoveURLWhitespace(in_relative, in_relative_length, | 296 const CHAR* relative = RemoveURLWhitespace( |
300 &whitespace_buffer, | 297 in_relative, in_relative_length, &whitespace_buffer, &relative_length, |
301 &relative_length); | 298 &output_parsed->potentially_dangling_markup); |
302 if (in_relative_length != relative_length) | |
303 output_parsed->whitespace_removed = true; | |
304 | 299 |
305 bool base_is_authority_based = false; | 300 bool base_is_authority_based = false; |
306 bool base_is_hierarchical = false; | 301 bool base_is_hierarchical = false; |
307 if (base_spec && | 302 if (base_spec && |
308 base_parsed.scheme.is_nonempty()) { | 303 base_parsed.scheme.is_nonempty()) { |
309 int after_scheme = base_parsed.scheme.end() + 1; // Skip past the colon. | 304 int after_scheme = base_parsed.scheme.end() + 1; // Skip past the colon. |
310 int num_slashes = CountConsecutiveSlashes(base_spec, after_scheme, | 305 int num_slashes = CountConsecutiveSlashes(base_spec, after_scheme, |
311 base_spec_len); | 306 base_spec_len); |
312 base_is_authority_based = num_slashes > 1; | 307 base_is_authority_based = num_slashes > 1; |
313 base_is_hierarchical = num_slashes > 0; | 308 base_is_hierarchical = num_slashes > 0; |
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
856 return DoCompareSchemeComponent(spec, component, compare_to); | 851 return DoCompareSchemeComponent(spec, component, compare_to); |
857 } | 852 } |
858 | 853 |
859 bool CompareSchemeComponent(const base::char16* spec, | 854 bool CompareSchemeComponent(const base::char16* spec, |
860 const Component& component, | 855 const Component& component, |
861 const char* compare_to) { | 856 const char* compare_to) { |
862 return DoCompareSchemeComponent(spec, component, compare_to); | 857 return DoCompareSchemeComponent(spec, component, compare_to); |
863 } | 858 } |
864 | 859 |
865 } // namespace url | 860 } // namespace url |
OLD | NEW |