link.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. "use strict";
  2. /**
  3. * @license
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. Object.defineProperty(exports, "__esModule", { value: true });
  7. exports.setHrefAndRel = void 0;
  8. var url_sanitizer_1 = require("../../builders/url_sanitizer");
  9. var resource_url_impl_1 = require("../../internals/resource_url_impl");
  10. var SAFE_URL_REL_VALUES = [
  11. 'alternate',
  12. 'author',
  13. 'bookmark',
  14. 'canonical',
  15. 'cite',
  16. 'help',
  17. 'icon',
  18. 'license',
  19. 'next',
  20. 'prefetch',
  21. 'dns-prefetch',
  22. 'prerender',
  23. 'preconnect',
  24. 'preload',
  25. 'prev',
  26. 'search',
  27. 'subresource',
  28. ];
  29. function setHrefAndRel(link, url, rel) {
  30. if (url instanceof resource_url_impl_1.TrustedResourceUrl) {
  31. link.href = (0, resource_url_impl_1.unwrapResourceUrl)(url).toString();
  32. }
  33. else {
  34. if (SAFE_URL_REL_VALUES.indexOf(rel) === -1) {
  35. throw new Error("TrustedResourceUrl href attribute required with rel=\"".concat(rel, "\""));
  36. }
  37. var sanitizedUrl = (0, url_sanitizer_1.unwrapUrlOrSanitize)(url);
  38. if (sanitizedUrl === undefined) {
  39. return;
  40. }
  41. link.href = sanitizedUrl;
  42. }
  43. link.rel = rel;
  44. }
  45. exports.setHrefAndRel = setHrefAndRel;