url_canon_relative.cc 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  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
  3. // found in the LICENSE file.
  4. // Canonicalizer functions for working with and resolving relative URLs.
  5. #include <algorithm>
  6. #include <ostream>
  7. #include "base/check_op.h"
  8. #include "base/strings/string_util.h"
  9. #include "url/url_canon.h"
  10. #include "url/url_canon_internal.h"
  11. #include "url/url_constants.h"
  12. #include "url/url_file.h"
  13. #include "url/url_parse_internal.h"
  14. #include "url/url_util.h"
  15. #include "url/url_util_internal.h"
  16. namespace url {
  17. namespace {
  18. // Firefox does a case-sensitive compare (which is probably wrong--Mozilla bug
  19. // 379034), whereas IE is case-insensitive.
  20. //
  21. // We choose to be more permissive like IE. We don't need to worry about
  22. // unescaping or anything here: neither IE or Firefox allow this. We also
  23. // don't have to worry about invalid scheme characters since we are comparing
  24. // against the canonical scheme of the base.
  25. //
  26. // The base URL should always be canonical, therefore it should be ASCII.
  27. template<typename CHAR>
  28. bool AreSchemesEqual(const char* base,
  29. const Component& base_scheme,
  30. const CHAR* cmp,
  31. const Component& cmp_scheme) {
  32. if (base_scheme.len != cmp_scheme.len)
  33. return false;
  34. for (int i = 0; i < base_scheme.len; i++) {
  35. // We assume the base is already canonical, so we don't have to
  36. // canonicalize it.
  37. if (CanonicalSchemeChar(cmp[cmp_scheme.begin + i]) !=
  38. base[base_scheme.begin + i])
  39. return false;
  40. }
  41. return true;
  42. }
  43. #ifdef WIN32
  44. // Here, we also allow Windows paths to be represented as "/C:/" so we can be
  45. // consistent about URL paths beginning with slashes. This function is like
  46. // DoesBeginWindowsDrivePath except that it also requires a slash at the
  47. // beginning.
  48. template<typename CHAR>
  49. bool DoesBeginSlashWindowsDriveSpec(const CHAR* spec, int start_offset,
  50. int spec_len) {
  51. if (start_offset >= spec_len)
  52. return false;
  53. return IsURLSlash(spec[start_offset]) &&
  54. DoesBeginWindowsDriveSpec(spec, start_offset + 1, spec_len);
  55. }
  56. #endif // WIN32
  57. template <typename CHAR>
  58. bool IsValidScheme(const CHAR* url, const Component& scheme) {
  59. // Caller should ensure that the |scheme| is not empty.
  60. DCHECK_NE(0, scheme.len);
  61. // From https://url.spec.whatwg.org/#scheme-start-state:
  62. // scheme start state:
  63. // 1. If c is an ASCII alpha, append c, lowercased, to buffer, and set
  64. // state to scheme state.
  65. // 2. Otherwise, if state override is not given, set state to no scheme
  66. // state, and decrease pointer by one.
  67. // 3. Otherwise, validation error, return failure.
  68. // Note that both step 2 and step 3 mean that the scheme was not valid.
  69. if (!base::IsAsciiAlpha(url[scheme.begin]))
  70. return false;
  71. // From https://url.spec.whatwg.org/#scheme-state:
  72. // scheme state:
  73. // 1. If c is an ASCII alphanumeric, U+002B (+), U+002D (-), or U+002E
  74. // (.), append c, lowercased, to buffer.
  75. // 2. Otherwise, if c is U+003A (:), then [...]
  76. //
  77. // We begin at |scheme.begin + 1|, because the character at |scheme.begin| has
  78. // already been checked by base::IsAsciiAlpha above.
  79. int scheme_end = scheme.end();
  80. for (int i = scheme.begin + 1; i < scheme_end; i++) {
  81. if (!CanonicalSchemeChar(url[i]))
  82. return false;
  83. }
  84. return true;
  85. }
  86. // See IsRelativeURL in the header file for usage.
  87. template<typename CHAR>
  88. bool DoIsRelativeURL(const char* base,
  89. const Parsed& base_parsed,
  90. const CHAR* url,
  91. int url_len,
  92. bool is_base_hierarchical,
  93. bool* is_relative,
  94. Component* relative_component) {
  95. *is_relative = false; // So we can default later to not relative.
  96. // Trim whitespace and construct a new range for the substring.
  97. int begin = 0;
  98. TrimURL(url, &begin, &url_len);
  99. if (begin >= url_len) {
  100. // Empty URLs are relative, but do nothing.
  101. if (!is_base_hierarchical) {
  102. // Don't allow relative URLs if the base scheme doesn't support it.
  103. return false;
  104. }
  105. *relative_component = Component(begin, 0);
  106. *is_relative = true;
  107. return true;
  108. }
  109. #ifdef WIN32
  110. // We special case paths like "C:\foo" so they can link directly to the
  111. // file on Windows (IE compatibility). The security domain stuff should
  112. // prevent a link like this from actually being followed if its on a
  113. // web page.
  114. //
  115. // We treat "C:/foo" as an absolute URL. We can go ahead and treat "/c:/"
  116. // as relative, as this will just replace the path when the base scheme
  117. // is a file and the answer will still be correct.
  118. //
  119. // We require strict backslashes when detecting UNC since two forward
  120. // slashes should be treated a a relative URL with a hostname.
  121. if (DoesBeginWindowsDriveSpec(url, begin, url_len) ||
  122. DoesBeginUNCPath(url, begin, url_len, true))
  123. return true;
  124. #endif // WIN32
  125. // See if we've got a scheme, if not, we know this is a relative URL.
  126. // BUT, just because we have a scheme, doesn't make it absolute.
  127. // "http:foo.html" is a relative URL with path "foo.html". If the scheme is
  128. // empty, we treat it as relative (":foo"), like IE does.
  129. Component scheme;
  130. const bool scheme_is_empty =
  131. !ExtractScheme(url, url_len, &scheme) || scheme.len == 0;
  132. if (scheme_is_empty) {
  133. if (url[begin] == '#') {
  134. // |url| is a bare fragment (e.g. "#foo"). This can be resolved against
  135. // any base. Fall-through.
  136. } else if (!is_base_hierarchical) {
  137. // Don't allow relative URLs if the base scheme doesn't support it.
  138. return false;
  139. }
  140. *relative_component = MakeRange(begin, url_len);
  141. *is_relative = true;
  142. return true;
  143. }
  144. // If the scheme isn't valid, then it's relative.
  145. if (!IsValidScheme(url, scheme)) {
  146. if (!is_base_hierarchical) {
  147. // Don't allow relative URLs if the base scheme doesn't support it.
  148. return false;
  149. }
  150. *relative_component = MakeRange(begin, url_len);
  151. *is_relative = true;
  152. return true;
  153. }
  154. // If the scheme is not the same, then we can't count it as relative.
  155. if (!AreSchemesEqual(base, base_parsed.scheme, url, scheme))
  156. return true;
  157. // When the scheme that they both share is not hierarchical, treat the
  158. // incoming scheme as absolute (this way with the base of "data:foo",
  159. // "data:bar" will be reported as absolute.
  160. if (!is_base_hierarchical)
  161. return true;
  162. int colon_offset = scheme.end();
  163. // If it's a filesystem URL, the only valid way to make it relative is not to
  164. // supply a scheme. There's no equivalent to e.g. http:index.html.
  165. if (CompareSchemeComponent(url, scheme, kFileSystemScheme))
  166. return true;
  167. // ExtractScheme guarantees that the colon immediately follows what it
  168. // considers to be the scheme. CountConsecutiveSlashes will handle the
  169. // case where the begin offset is the end of the input.
  170. int num_slashes = CountConsecutiveSlashes(url, colon_offset + 1, url_len);
  171. if (num_slashes == 0 || num_slashes == 1) {
  172. // No slashes means it's a relative path like "http:foo.html". One slash
  173. // is an absolute path. "http:/home/foo.html"
  174. *is_relative = true;
  175. *relative_component = MakeRange(colon_offset + 1, url_len);
  176. return true;
  177. }
  178. // Two or more slashes after the scheme we treat as absolute.
  179. return true;
  180. }
  181. // Copies all characters in the range [begin, end) of |spec| to the output,
  182. // up until and including the last slash. There should be a slash in the
  183. // range, if not, nothing will be copied.
  184. //
  185. // For stardard URLs the input should be canonical, but when resolving relative
  186. // URLs on a non-standard base (like "data:") the input can be anything.
  187. void CopyToLastSlash(const char* spec,
  188. int begin,
  189. int end,
  190. CanonOutput* output) {
  191. // Find the last slash.
  192. int last_slash = -1;
  193. for (int i = end - 1; i >= begin; i--) {
  194. if (spec[i] == '/' || spec[i] == '\\') {
  195. last_slash = i;
  196. break;
  197. }
  198. }
  199. if (last_slash < 0)
  200. return; // No slash.
  201. // Copy.
  202. for (int i = begin; i <= last_slash; i++)
  203. output->push_back(spec[i]);
  204. }
  205. // Copies a single component from the source to the output. This is used
  206. // when resolving relative URLs and a given component is unchanged. Since the
  207. // source should already be canonical, we don't have to do anything special,
  208. // and the input is ASCII.
  209. void CopyOneComponent(const char* source,
  210. const Component& source_component,
  211. CanonOutput* output,
  212. Component* output_component) {
  213. if (source_component.len < 0) {
  214. // This component is not present.
  215. *output_component = Component();
  216. return;
  217. }
  218. output_component->begin = output->length();
  219. int source_end = source_component.end();
  220. for (int i = source_component.begin; i < source_end; i++)
  221. output->push_back(source[i]);
  222. output_component->len = output->length() - output_component->begin;
  223. }
  224. #ifdef WIN32
  225. // Called on Windows when the base URL is a file URL, this will copy the "C:"
  226. // to the output, if there is a drive letter and if that drive letter is not
  227. // being overridden by the relative URL. Otherwise, do nothing.
  228. //
  229. // It will return the index of the beginning of the next character in the
  230. // base to be processed: if there is a "C:", the slash after it, or if
  231. // there is no drive letter, the slash at the beginning of the path, or
  232. // the end of the base. This can be used as the starting offset for further
  233. // path processing.
  234. template<typename CHAR>
  235. int CopyBaseDriveSpecIfNecessary(const char* base_url,
  236. int base_path_begin,
  237. int base_path_end,
  238. const CHAR* relative_url,
  239. int path_start,
  240. int relative_url_len,
  241. CanonOutput* output) {
  242. if (base_path_begin >= base_path_end)
  243. return base_path_begin; // No path.
  244. // If the relative begins with a drive spec, don't do anything. The existing
  245. // drive spec in the base will be replaced.
  246. if (DoesBeginWindowsDriveSpec(relative_url, path_start, relative_url_len)) {
  247. return base_path_begin; // Relative URL path is "C:/foo"
  248. }
  249. // The path should begin with a slash (as all canonical paths do). We check
  250. // if it is followed by a drive letter and copy it.
  251. if (DoesBeginSlashWindowsDriveSpec(base_url,
  252. base_path_begin,
  253. base_path_end)) {
  254. // Copy the two-character drive spec to the output. It will now look like
  255. // "file:///C:" so the rest of it can be treated like a standard path.
  256. output->push_back('/');
  257. output->push_back(base_url[base_path_begin + 1]);
  258. output->push_back(base_url[base_path_begin + 2]);
  259. return base_path_begin + 3;
  260. }
  261. return base_path_begin;
  262. }
  263. #endif // WIN32
  264. // A subroutine of DoResolveRelativeURL, this resolves the URL knowning that
  265. // the input is a relative path or less (query or ref).
  266. template<typename CHAR>
  267. bool DoResolveRelativePath(const char* base_url,
  268. const Parsed& base_parsed,
  269. bool base_is_file,
  270. const CHAR* relative_url,
  271. const Component& relative_component,
  272. CharsetConverter* query_converter,
  273. CanonOutput* output,
  274. Parsed* out_parsed) {
  275. bool success = true;
  276. // We know the authority section didn't change, copy it to the output. We
  277. // also know we have a path so can copy up to there.
  278. Component path, query, ref;
  279. ParsePathInternal(relative_url, relative_component, &path, &query, &ref);
  280. // Canonical URLs always have a path, so we can use that offset. Reserve
  281. // enough room for the base URL, the new path, and some extra bytes for
  282. // possible escaped characters.
  283. output->ReserveSizeIfNeeded(base_parsed.path.begin +
  284. std::max({path.end(), query.end(), ref.end()}));
  285. output->Append(base_url, base_parsed.path.begin);
  286. if (path.len > 0) {
  287. // The path is replaced or modified.
  288. int true_path_begin = output->length();
  289. // For file: URLs on Windows, we don't want to treat the drive letter and
  290. // colon as part of the path for relative file resolution when the
  291. // incoming URL does not provide a drive spec. We save the true path
  292. // beginning so we can fix it up after we are done.
  293. int base_path_begin = base_parsed.path.begin;
  294. #ifdef WIN32
  295. if (base_is_file) {
  296. base_path_begin = CopyBaseDriveSpecIfNecessary(
  297. base_url, base_parsed.path.begin, base_parsed.path.end(),
  298. relative_url, relative_component.begin, relative_component.end(),
  299. output);
  300. // Now the output looks like either "file://" or "file:///C:"
  301. // and we can start appending the rest of the path. |base_path_begin|
  302. // points to the character in the base that comes next.
  303. }
  304. #endif // WIN32
  305. if (IsURLSlash(relative_url[path.begin])) {
  306. // Easy case: the path is an absolute path on the server, so we can
  307. // just replace everything from the path on with the new versions.
  308. // Since the input should be canonical hierarchical URL, we should
  309. // always have a path.
  310. success &= CanonicalizePath(relative_url, path,
  311. output, &out_parsed->path);
  312. } else {
  313. // Relative path, replace the query, and reference. We take the
  314. // original path with the file part stripped, and append the new path.
  315. // The canonicalizer will take care of resolving ".." and "."
  316. size_t path_begin = output->length();
  317. CopyToLastSlash(base_url, base_path_begin, base_parsed.path.end(),
  318. output);
  319. success &= CanonicalizePartialPathInternal(relative_url, path, path_begin,
  320. output);
  321. out_parsed->path = MakeRange(path_begin, output->length());
  322. // Copy the rest of the stuff after the path from the relative path.
  323. }
  324. // Finish with the query and reference part (these can't fail).
  325. CanonicalizeQuery(relative_url, query, query_converter,
  326. output, &out_parsed->query);
  327. CanonicalizeRef(relative_url, ref, output, &out_parsed->ref);
  328. // Fix the path beginning to add back the "C:" we may have written above.
  329. out_parsed->path = MakeRange(true_path_begin, out_parsed->path.end());
  330. return success;
  331. }
  332. // If we get here, the path is unchanged: copy to output.
  333. CopyOneComponent(base_url, base_parsed.path, output, &out_parsed->path);
  334. if (query.is_valid()) {
  335. // Just the query specified, replace the query and reference (ignore
  336. // failures for refs)
  337. CanonicalizeQuery(relative_url, query, query_converter,
  338. output, &out_parsed->query);
  339. CanonicalizeRef(relative_url, ref, output, &out_parsed->ref);
  340. return success;
  341. }
  342. // If we get here, the query is unchanged: copy to output. Note that the
  343. // range of the query parameter doesn't include the question mark, so we
  344. // have to add it manually if there is a component.
  345. if (base_parsed.query.is_valid())
  346. output->push_back('?');
  347. CopyOneComponent(base_url, base_parsed.query, output, &out_parsed->query);
  348. if (ref.is_valid()) {
  349. // Just the reference specified: replace it (ignoring failures).
  350. CanonicalizeRef(relative_url, ref, output, &out_parsed->ref);
  351. return success;
  352. }
  353. // We should always have something to do in this function, the caller checks
  354. // that some component is being replaced.
  355. DCHECK(false) << "Not reached";
  356. return success;
  357. }
  358. // Resolves a relative URL that contains a host. Typically, these will
  359. // be of the form "//www.google.com/foo/bar?baz#ref" and the only thing which
  360. // should be kept from the original URL is the scheme.
  361. template<typename CHAR>
  362. bool DoResolveRelativeHost(const char* base_url,
  363. const Parsed& base_parsed,
  364. const CHAR* relative_url,
  365. const Component& relative_component,
  366. CharsetConverter* query_converter,
  367. CanonOutput* output,
  368. Parsed* out_parsed) {
  369. // Parse the relative URL, just like we would for anything following a
  370. // scheme.
  371. Parsed relative_parsed; // Everything but the scheme is valid.
  372. ParseAfterScheme(relative_url, relative_component.end(),
  373. relative_component.begin, &relative_parsed);
  374. // Now we can just use the replacement function to replace all the necessary
  375. // parts of the old URL with the new one.
  376. Replacements<CHAR> replacements;
  377. replacements.SetUsername(relative_url, relative_parsed.username);
  378. replacements.SetPassword(relative_url, relative_parsed.password);
  379. replacements.SetHost(relative_url, relative_parsed.host);
  380. replacements.SetPort(relative_url, relative_parsed.port);
  381. replacements.SetPath(relative_url, relative_parsed.path);
  382. replacements.SetQuery(relative_url, relative_parsed.query);
  383. replacements.SetRef(relative_url, relative_parsed.ref);
  384. // Length() does not include the old scheme, so make sure to add it from the
  385. // base URL.
  386. output->ReserveSizeIfNeeded(
  387. replacements.components().Length() +
  388. base_parsed.CountCharactersBefore(Parsed::USERNAME, false));
  389. SchemeType scheme_type = SCHEME_WITH_HOST_PORT_AND_USER_INFORMATION;
  390. if (!GetStandardSchemeType(base_url, base_parsed.scheme, &scheme_type)) {
  391. // A path with an authority section gets canonicalized under standard URL
  392. // rules, even though the base was not known to be standard.
  393. scheme_type = SCHEME_WITH_HOST_PORT_AND_USER_INFORMATION;
  394. }
  395. return ReplaceStandardURL(base_url, base_parsed, replacements, scheme_type,
  396. query_converter, output, out_parsed);
  397. }
  398. // Resolves a relative URL that happens to be an absolute file path. Examples
  399. // include: "//hostname/path", "/c:/foo", and "//hostname/c:/foo".
  400. template<typename CHAR>
  401. bool DoResolveAbsoluteFile(const CHAR* relative_url,
  402. const Component& relative_component,
  403. CharsetConverter* query_converter,
  404. CanonOutput* output,
  405. Parsed* out_parsed) {
  406. // Parse the file URL. The file URl parsing function uses the same logic
  407. // as we do for determining if the file is absolute, in which case it will
  408. // not bother to look for a scheme.
  409. Parsed relative_parsed;
  410. ParseFileURL(&relative_url[relative_component.begin], relative_component.len,
  411. &relative_parsed);
  412. return CanonicalizeFileURL(&relative_url[relative_component.begin],
  413. relative_component.len, relative_parsed,
  414. query_converter, output, out_parsed);
  415. }
  416. // TODO(brettw) treat two slashes as root like Mozilla for FTP?
  417. template<typename CHAR>
  418. bool DoResolveRelativeURL(const char* base_url,
  419. const Parsed& base_parsed,
  420. bool base_is_file,
  421. const CHAR* relative_url,
  422. const Component& relative_component,
  423. CharsetConverter* query_converter,
  424. CanonOutput* output,
  425. Parsed* out_parsed) {
  426. // |base_parsed| is the starting point for our output. Since we may have
  427. // removed whitespace from |relative_url| before entering this method, we'll
  428. // carry over the |potentially_dangling_markup| flag.
  429. bool potentially_dangling_markup = out_parsed->potentially_dangling_markup;
  430. *out_parsed = base_parsed;
  431. if (potentially_dangling_markup)
  432. out_parsed->potentially_dangling_markup = true;
  433. // Sanity check: the input should have a host or we'll break badly below.
  434. // We can only resolve relative URLs with base URLs that have hosts and
  435. // paths (even the default path of "/" is OK).
  436. //
  437. // We allow hosts with no length so we can handle file URLs, for example.
  438. if (base_parsed.path.len <= 0) {
  439. // On error, return the input (resolving a relative URL on a non-relative
  440. // base = the base).
  441. int base_len = base_parsed.Length();
  442. for (int i = 0; i < base_len; i++)
  443. output->push_back(base_url[i]);
  444. return false;
  445. }
  446. if (relative_component.len <= 0) {
  447. // Empty relative URL, leave unchanged, only removing the ref component.
  448. int base_len = base_parsed.Length();
  449. base_len -= base_parsed.ref.len + 1;
  450. out_parsed->ref.reset();
  451. output->Append(base_url, base_len);
  452. return true;
  453. }
  454. int num_slashes = CountConsecutiveSlashes(
  455. relative_url, relative_component.begin, relative_component.end());
  456. #ifdef WIN32
  457. // On Windows, two slashes for a file path (regardless of which direction
  458. // they are) means that it's UNC. Two backslashes on any base scheme mean
  459. // that it's an absolute UNC path (we use the base_is_file flag to control
  460. // how strict the UNC finder is).
  461. //
  462. // We also allow Windows absolute drive specs on any scheme (for example
  463. // "c:\foo") like IE does. There must be no preceding slashes in this
  464. // case (we reject anything like "/c:/foo") because that should be treated
  465. // as a path. For file URLs, we allow any number of slashes since that would
  466. // be setting the path.
  467. //
  468. // This assumes the absolute path resolver handles absolute URLs like this
  469. // properly. DoCanonicalize does this.
  470. int after_slashes = relative_component.begin + num_slashes;
  471. if (DoesBeginUNCPath(relative_url, relative_component.begin,
  472. relative_component.end(), !base_is_file) ||
  473. ((num_slashes == 0 || base_is_file) &&
  474. DoesBeginWindowsDriveSpec(
  475. relative_url, after_slashes, relative_component.end()))) {
  476. return DoResolveAbsoluteFile(relative_url, relative_component,
  477. query_converter, output, out_parsed);
  478. }
  479. #else
  480. // Other platforms need explicit handling for file: URLs with multiple
  481. // slashes because the generic scheme parsing always extracts a host, but a
  482. // file: URL only has a host if it has exactly 2 slashes. Even if it does
  483. // have a host, we want to use the special host detection logic for file
  484. // URLs provided by DoResolveAbsoluteFile(), as opposed to the generic host
  485. // detection logic, for consistency with parsing file URLs from scratch.
  486. if (base_is_file && num_slashes >= 2) {
  487. return DoResolveAbsoluteFile(relative_url, relative_component,
  488. query_converter, output, out_parsed);
  489. }
  490. #endif
  491. // Any other double-slashes mean that this is relative to the scheme.
  492. if (num_slashes >= 2) {
  493. return DoResolveRelativeHost(base_url, base_parsed,
  494. relative_url, relative_component,
  495. query_converter, output, out_parsed);
  496. }
  497. // When we get here, we know that the relative URL is on the same host.
  498. return DoResolveRelativePath(base_url, base_parsed, base_is_file,
  499. relative_url, relative_component,
  500. query_converter, output, out_parsed);
  501. }
  502. } // namespace
  503. bool IsRelativeURL(const char* base,
  504. const Parsed& base_parsed,
  505. const char* fragment,
  506. int fragment_len,
  507. bool is_base_hierarchical,
  508. bool* is_relative,
  509. Component* relative_component) {
  510. return DoIsRelativeURL<char>(
  511. base, base_parsed, fragment, fragment_len, is_base_hierarchical,
  512. is_relative, relative_component);
  513. }
  514. bool IsRelativeURL(const char* base,
  515. const Parsed& base_parsed,
  516. const char16_t* fragment,
  517. int fragment_len,
  518. bool is_base_hierarchical,
  519. bool* is_relative,
  520. Component* relative_component) {
  521. return DoIsRelativeURL<char16_t>(base, base_parsed, fragment, fragment_len,
  522. is_base_hierarchical, is_relative,
  523. relative_component);
  524. }
  525. bool ResolveRelativeURL(const char* base_url,
  526. const Parsed& base_parsed,
  527. bool base_is_file,
  528. const char* relative_url,
  529. const Component& relative_component,
  530. CharsetConverter* query_converter,
  531. CanonOutput* output,
  532. Parsed* out_parsed) {
  533. return DoResolveRelativeURL<char>(
  534. base_url, base_parsed, base_is_file, relative_url,
  535. relative_component, query_converter, output, out_parsed);
  536. }
  537. bool ResolveRelativeURL(const char* base_url,
  538. const Parsed& base_parsed,
  539. bool base_is_file,
  540. const char16_t* relative_url,
  541. const Component& relative_component,
  542. CharsetConverter* query_converter,
  543. CanonOutput* output,
  544. Parsed* out_parsed) {
  545. return DoResolveRelativeURL<char16_t>(base_url, base_parsed, base_is_file,
  546. relative_url, relative_component,
  547. query_converter, output, out_parsed);
  548. }
  549. } // namespace url