// Copyright 2013 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include <string_view> #include "base/check.h" #include "url/third_party/mozilla/url_parse.h" #include "url/url_file.h" #include "url/url_parse_internal.h" // Interesting IE file:isms... // // INPUT OUTPUT // ========================= ============================== // file:/foo/bar file:///foo/bar // The result here seems totally invalid!?!? This isn't UNC. // // file:/ // file:// or any other number of slashes // IE6 doesn't do anything at all if you click on this link. No error: // nothing. IE6's history system seems to always color this link, so I'm // guessing that it maps internally to the empty URL. // // C:\ file:///C:/ // When on a file: URL source page, this link will work. When over HTTP, // the file: URL will appear in the status bar but the link will not work // (security restriction for all file URLs). // // file:foo/ file:foo/ (invalid?!?!?) // file:/foo/ file:///foo/ (invalid?!?!?) // file://foo/ file://foo/ (UNC to server "foo") // file:///foo/ file:///foo/ (invalid, seems to be a file) // file:////foo/ file://foo/ (UNC to server "foo") // Any more than four slashes is also treated as UNC. // // file:C:/ file://C:/ // file:/C:/ file://C:/ // The number of slashes after "file:" don't matter if the thing following // it looks like an absolute drive path. Also, slashes and backslashes are // equally valid here. namespace url { namespace { // Returns the index of the next slash in the input after the given index, or // `spec.size()` if the end of the input is reached. template <typename CharT> size_t FindNextSlash(std::basic_string_view<CharT> spec, size_t begin_index) { … } // A subcomponent of DoParseFileURL, the input of this function should be a UNC // path name, with the index of the first character after the slashes following // the scheme given in `after_slashes`. This will initialize the host, path, // query, and ref, and leave the other output components untouched // (DoParseFileURL handles these for us). template <typename CharT> void DoParseUNC(std::basic_string_view<CharT> url, size_t after_slashes, Parsed* parsed) { … } // A subcomponent of DoParseFileURL, the input should be a local file, with the // beginning of the path indicated by the index in `path_begin`. This will // initialize the host, path, query, and ref, and leave the other output // components untouched (DoParseFileURL handles these for us). template <typename CharT> void DoParseLocalFile(std::basic_string_view<CharT> url, int path_begin, Parsed* parsed) { … } // Backend for the external functions that operates on either char type. // Handles cases where there is a scheme, but also when handed the first // character following the "file:" at the beginning of the spec. If so, // this is usually a slash, but needn't be; we allow paths like "file:c:\foo". template <typename CharT> Parsed DoParseFileURL(std::basic_string_view<CharT> url) { … } } // namespace Parsed ParseFileURL(std::string_view url) { … } Parsed ParseFileURL(std::u16string_view url) { … } } // namespace url