@p4ulcristian/iris-layout 0.2.0 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cljs-runtime/cljs.core.js +38746 -0
- package/dist/cljs-runtime/cljs.core.js.map +1 -0
- package/dist/cljs-runtime/cljs.pprint.js +8400 -0
- package/dist/cljs-runtime/cljs.pprint.js.map +1 -0
- package/dist/cljs-runtime/cljs.stacktrace.js +561 -0
- package/dist/cljs-runtime/cljs.stacktrace.js.map +1 -0
- package/dist/cljs-runtime/cljs_env.js +1286 -0
- package/dist/cljs-runtime/clojure.data.js +295 -0
- package/dist/cljs-runtime/clojure.data.js.map +1 -0
- package/dist/cljs-runtime/clojure.set.js +382 -0
- package/dist/cljs-runtime/clojure.set.js.map +1 -0
- package/dist/cljs-runtime/clojure.string.js +480 -0
- package/dist/cljs-runtime/clojure.string.js.map +1 -0
- package/dist/cljs-runtime/clojure.walk.js +132 -0
- package/dist/cljs-runtime/clojure.walk.js.map +1 -0
- package/dist/cljs-runtime/devtools.async.js +90 -0
- package/dist/cljs-runtime/devtools.async.js.map +1 -0
- package/dist/cljs-runtime/devtools.context.js +11 -0
- package/dist/cljs-runtime/devtools.context.js.map +1 -0
- package/dist/cljs-runtime/devtools.core.js +175 -0
- package/dist/cljs-runtime/devtools.core.js.map +1 -0
- package/dist/cljs-runtime/devtools.defaults.js +20 -0
- package/dist/cljs-runtime/devtools.defaults.js.map +1 -0
- package/dist/cljs-runtime/devtools.format.js +631 -0
- package/dist/cljs-runtime/devtools.format.js.map +1 -0
- package/dist/cljs-runtime/devtools.formatters.budgeting.js +182 -0
- package/dist/cljs-runtime/devtools.formatters.budgeting.js.map +1 -0
- package/dist/cljs-runtime/devtools.formatters.core.js +220 -0
- package/dist/cljs-runtime/devtools.formatters.core.js.map +1 -0
- package/dist/cljs-runtime/devtools.formatters.helpers.js +228 -0
- package/dist/cljs-runtime/devtools.formatters.helpers.js.map +1 -0
- package/dist/cljs-runtime/devtools.formatters.js +261 -0
- package/dist/cljs-runtime/devtools.formatters.js.map +1 -0
- package/dist/cljs-runtime/devtools.formatters.markup.js +1174 -0
- package/dist/cljs-runtime/devtools.formatters.markup.js.map +1 -0
- package/dist/cljs-runtime/devtools.formatters.printing.js +313 -0
- package/dist/cljs-runtime/devtools.formatters.printing.js.map +1 -0
- package/dist/cljs-runtime/devtools.formatters.state.js +325 -0
- package/dist/cljs-runtime/devtools.formatters.state.js.map +1 -0
- package/dist/cljs-runtime/devtools.formatters.templating.js +666 -0
- package/dist/cljs-runtime/devtools.formatters.templating.js.map +1 -0
- package/dist/cljs-runtime/devtools.hints.js +193 -0
- package/dist/cljs-runtime/devtools.hints.js.map +1 -0
- package/dist/cljs-runtime/devtools.munging.js +1058 -0
- package/dist/cljs-runtime/devtools.munging.js.map +1 -0
- package/dist/cljs-runtime/devtools.prefs.js +87 -0
- package/dist/cljs-runtime/devtools.prefs.js.map +1 -0
- package/dist/cljs-runtime/devtools.preload.js +11 -0
- package/dist/cljs-runtime/devtools.preload.js.map +1 -0
- package/dist/cljs-runtime/devtools.protocols.js +98 -0
- package/dist/cljs-runtime/devtools.protocols.js.map +1 -0
- package/dist/cljs-runtime/devtools.reporter.js +81 -0
- package/dist/cljs-runtime/devtools.reporter.js.map +1 -0
- package/dist/cljs-runtime/devtools.toolbox.js +141 -0
- package/dist/cljs-runtime/devtools.toolbox.js.map +1 -0
- package/dist/cljs-runtime/devtools.util.js +517 -0
- package/dist/cljs-runtime/devtools.util.js.map +1 -0
- package/dist/cljs-runtime/devtools.version.js +9 -0
- package/dist/cljs-runtime/devtools.version.js.map +1 -0
- package/dist/cljs-runtime/goog.array.array.js +659 -0
- package/dist/cljs-runtime/goog.array.array.js.map +9 -0
- package/dist/cljs-runtime/goog.asserts.asserts.js +133 -0
- package/dist/cljs-runtime/goog.asserts.asserts.js.map +9 -0
- package/dist/cljs-runtime/goog.asserts.dom.js +90 -0
- package/dist/cljs-runtime/goog.asserts.dom.js.map +9 -0
- package/dist/cljs-runtime/goog.async.nexttick.js +93 -0
- package/dist/cljs-runtime/goog.async.nexttick.js.map +9 -0
- package/dist/cljs-runtime/goog.base.js +1261 -0
- package/dist/cljs-runtime/goog.base.js.map +9 -0
- package/dist/cljs-runtime/goog.collections.maps.js +82 -0
- package/dist/cljs-runtime/goog.collections.maps.js.map +9 -0
- package/dist/cljs-runtime/goog.debug.entrypointregistry.js +44 -0
- package/dist/cljs-runtime/goog.debug.entrypointregistry.js.map +9 -0
- package/dist/cljs-runtime/goog.debug.error.js +30 -0
- package/dist/cljs-runtime/goog.debug.error.js.map +9 -0
- package/dist/cljs-runtime/goog.dom.asserts.js +40 -0
- package/dist/cljs-runtime/goog.dom.asserts.js.map +9 -0
- package/dist/cljs-runtime/goog.dom.browserfeature.js +21 -0
- package/dist/cljs-runtime/goog.dom.browserfeature.js.map +9 -0
- package/dist/cljs-runtime/goog.dom.dom.js +1087 -0
- package/dist/cljs-runtime/goog.dom.dom.js.map +9 -0
- package/dist/cljs-runtime/goog.dom.element.js +69 -0
- package/dist/cljs-runtime/goog.dom.element.js.map +9 -0
- package/dist/cljs-runtime/goog.dom.htmlelement.js +7 -0
- package/dist/cljs-runtime/goog.dom.htmlelement.js.map +9 -0
- package/dist/cljs-runtime/goog.dom.nodetype.js +6 -0
- package/dist/cljs-runtime/goog.dom.nodetype.js.map +9 -0
- package/dist/cljs-runtime/goog.dom.safe.js +277 -0
- package/dist/cljs-runtime/goog.dom.safe.js.map +9 -0
- package/dist/cljs-runtime/goog.dom.tagname.js +147 -0
- package/dist/cljs-runtime/goog.dom.tagname.js.map +9 -0
- package/dist/cljs-runtime/goog.dom.tags.js +10 -0
- package/dist/cljs-runtime/goog.dom.tags.js.map +9 -0
- package/dist/cljs-runtime/goog.flags.flags.js +12 -0
- package/dist/cljs-runtime/goog.flags.flags.js.map +9 -0
- package/dist/cljs-runtime/goog.fs.blob.js +38 -0
- package/dist/cljs-runtime/goog.fs.blob.js.map +9 -0
- package/dist/cljs-runtime/goog.fs.url.js +37 -0
- package/dist/cljs-runtime/goog.fs.url.js.map +9 -0
- package/dist/cljs-runtime/goog.functions.functions.js +211 -0
- package/dist/cljs-runtime/goog.functions.functions.js.map +9 -0
- package/dist/cljs-runtime/goog.html.safehtml.js +321 -0
- package/dist/cljs-runtime/goog.html.safehtml.js.map +9 -0
- package/dist/cljs-runtime/goog.html.safescript.js +65 -0
- package/dist/cljs-runtime/goog.html.safescript.js.map +9 -0
- package/dist/cljs-runtime/goog.html.safestyle.js +175 -0
- package/dist/cljs-runtime/goog.html.safestyle.js.map +9 -0
- package/dist/cljs-runtime/goog.html.safestylesheet.js +99 -0
- package/dist/cljs-runtime/goog.html.safestylesheet.js.map +9 -0
- package/dist/cljs-runtime/goog.html.safeurl.js +231 -0
- package/dist/cljs-runtime/goog.html.safeurl.js.map +9 -0
- package/dist/cljs-runtime/goog.html.trustedresourceurl.js +123 -0
- package/dist/cljs-runtime/goog.html.trustedresourceurl.js.map +9 -0
- package/dist/cljs-runtime/goog.html.trustedtypes.js +16 -0
- package/dist/cljs-runtime/goog.html.trustedtypes.js.map +9 -0
- package/dist/cljs-runtime/goog.html.uncheckedconversions.js +52 -0
- package/dist/cljs-runtime/goog.html.uncheckedconversions.js.map +9 -0
- package/dist/cljs-runtime/goog.labs.useragent.browser.js +352 -0
- package/dist/cljs-runtime/goog.labs.useragent.browser.js.map +9 -0
- package/dist/cljs-runtime/goog.labs.useragent.engine.js +73 -0
- package/dist/cljs-runtime/goog.labs.useragent.engine.js.map +9 -0
- package/dist/cljs-runtime/goog.labs.useragent.highentropy.highentropydata.js +14 -0
- package/dist/cljs-runtime/goog.labs.useragent.highentropy.highentropydata.js.map +9 -0
- package/dist/cljs-runtime/goog.labs.useragent.highentropy.highentropyvalue.js +74 -0
- package/dist/cljs-runtime/goog.labs.useragent.highentropy.highentropyvalue.js.map +9 -0
- package/dist/cljs-runtime/goog.labs.useragent.platform.js +147 -0
- package/dist/cljs-runtime/goog.labs.useragent.platform.js.map +9 -0
- package/dist/cljs-runtime/goog.labs.useragent.useragent.js +21 -0
- package/dist/cljs-runtime/goog.labs.useragent.useragent.js.map +9 -0
- package/dist/cljs-runtime/goog.labs.useragent.util.js +81 -0
- package/dist/cljs-runtime/goog.labs.useragent.util.js.map +9 -0
- package/dist/cljs-runtime/goog.math.coordinate.js +97 -0
- package/dist/cljs-runtime/goog.math.coordinate.js.map +9 -0
- package/dist/cljs-runtime/goog.math.integer.js +445 -0
- package/dist/cljs-runtime/goog.math.integer.js.map +9 -0
- package/dist/cljs-runtime/goog.math.long.js +437 -0
- package/dist/cljs-runtime/goog.math.long.js.map +9 -0
- package/dist/cljs-runtime/goog.math.math.js +158 -0
- package/dist/cljs-runtime/goog.math.math.js.map +9 -0
- package/dist/cljs-runtime/goog.math.size.js +76 -0
- package/dist/cljs-runtime/goog.math.size.js.map +9 -0
- package/dist/cljs-runtime/goog.object.object.js +284 -0
- package/dist/cljs-runtime/goog.object.object.js.map +9 -0
- package/dist/cljs-runtime/goog.reflect.reflect.js +32 -0
- package/dist/cljs-runtime/goog.reflect.reflect.js.map +9 -0
- package/dist/cljs-runtime/goog.string.const.js +35 -0
- package/dist/cljs-runtime/goog.string.const.js.map +9 -0
- package/dist/cljs-runtime/goog.string.internal.js +119 -0
- package/dist/cljs-runtime/goog.string.internal.js.map +9 -0
- package/dist/cljs-runtime/goog.string.string.js +462 -0
- package/dist/cljs-runtime/goog.string.string.js.map +9 -0
- package/dist/cljs-runtime/goog.string.stringbuffer.js +32 -0
- package/dist/cljs-runtime/goog.string.stringbuffer.js.map +9 -0
- package/dist/cljs-runtime/goog.string.typedstring.js +9 -0
- package/dist/cljs-runtime/goog.string.typedstring.js.map +9 -0
- package/dist/cljs-runtime/goog.structs.structs.js +199 -0
- package/dist/cljs-runtime/goog.structs.structs.js.map +9 -0
- package/dist/cljs-runtime/goog.uri.uri.js +628 -0
- package/dist/cljs-runtime/goog.uri.uri.js.map +9 -0
- package/dist/cljs-runtime/goog.uri.utils.js +326 -0
- package/dist/cljs-runtime/goog.uri.utils.js.map +9 -0
- package/dist/cljs-runtime/goog.useragent.useragent.js +139 -0
- package/dist/cljs-runtime/goog.useragent.useragent.js.map +9 -0
- package/dist/cljs-runtime/iris_layout.components.entity_card_group.js +202 -0
- package/dist/cljs-runtime/iris_layout.components.entity_card_group.js.map +1 -0
- package/dist/cljs-runtime/iris_layout.components.entity_tile.js +295 -0
- package/dist/cljs-runtime/iris_layout.components.entity_tile.js.map +1 -0
- package/dist/cljs-runtime/iris_layout.components.entity_tile_group.js +33 -0
- package/dist/cljs-runtime/iris_layout.components.entity_tile_group.js.map +1 -0
- package/dist/cljs-runtime/iris_layout.components.resizer.js +91 -0
- package/dist/cljs-runtime/iris_layout.components.resizer.js.map +1 -0
- package/dist/cljs-runtime/iris_layout.components.touch_drag.js +399 -0
- package/dist/cljs-runtime/iris_layout.components.touch_drag.js.map +1 -0
- package/dist/cljs-runtime/iris_layout.core.js +1372 -0
- package/dist/cljs-runtime/iris_layout.core.js.map +1 -0
- package/dist/cljs-runtime/iris_layout.layout.js +328 -0
- package/dist/cljs-runtime/iris_layout.layout.js.map +1 -0
- package/dist/cljs-runtime/reagent.core.js +993 -0
- package/dist/cljs-runtime/reagent.core.js.map +1 -0
- package/dist/cljs-runtime/reagent.debug.js +75 -0
- package/dist/cljs-runtime/reagent.debug.js.map +1 -0
- package/dist/cljs-runtime/reagent.impl.batching.js +270 -0
- package/dist/cljs-runtime/reagent.impl.batching.js.map +1 -0
- package/dist/cljs-runtime/reagent.impl.component.js +758 -0
- package/dist/cljs-runtime/reagent.impl.component.js.map +1 -0
- package/dist/cljs-runtime/reagent.impl.input.js +175 -0
- package/dist/cljs-runtime/reagent.impl.input.js.map +1 -0
- package/dist/cljs-runtime/reagent.impl.protocols.js +99 -0
- package/dist/cljs-runtime/reagent.impl.protocols.js.map +1 -0
- package/dist/cljs-runtime/reagent.impl.template.js +660 -0
- package/dist/cljs-runtime/reagent.impl.template.js.map +1 -0
- package/dist/cljs-runtime/reagent.impl.util.js +748 -0
- package/dist/cljs-runtime/reagent.impl.util.js.map +1 -0
- package/dist/cljs-runtime/reagent.ratom.js +1668 -0
- package/dist/cljs-runtime/reagent.ratom.js.map +1 -0
- package/dist/cljs-runtime/shadow.esm.esm_import$react.js +5 -0
- package/dist/cljs-runtime/shadow.module.iris-layout.append.js +2 -0
- package/dist/cljs-runtime/shadow.module.iris-layout.prepend.js +2 -0
- package/dist/iris-layout.js +375 -355
- package/dist/styles.css +287 -9
- package/package.json +1 -1
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import "./cljs_env.js";
|
|
2
|
+
import "./goog.string.const.js";
|
|
3
|
+
import "./goog.html.safeurl.js";
|
|
4
|
+
import "./goog.string.typedstring.js";
|
|
5
|
+
import "./goog.asserts.asserts.js";
|
|
6
|
+
import "./goog.string.internal.js";
|
|
7
|
+
goog.loadModule(function(exports) {
|
|
8
|
+
function sanitizePropertyValue(value) {
|
|
9
|
+
if (value instanceof SafeUrl) {
|
|
10
|
+
const url = SafeUrl.unwrap(value);
|
|
11
|
+
return 'url("' + url.replace(/</g, "%3c").replace(/[\\"]/g, "\\$\x26") + '")';
|
|
12
|
+
}
|
|
13
|
+
const result = value instanceof Const ? Const.unwrap(value) : sanitizePropertyValueString(String(value));
|
|
14
|
+
if (/[{;}]/.test(result)) {
|
|
15
|
+
throw new AssertionError("Value does not allow [{;}], got: %s.", [result]);
|
|
16
|
+
}
|
|
17
|
+
return result;
|
|
18
|
+
}
|
|
19
|
+
function sanitizePropertyValueString(value) {
|
|
20
|
+
const valueWithoutFunctions = value.replace(FUNCTIONS_RE, "$1").replace(FUNCTIONS_RE, "$1").replace(URL_RE, "url");
|
|
21
|
+
if (!VALUE_RE.test(valueWithoutFunctions)) {
|
|
22
|
+
fail(`String value allows only ${VALUE_ALLOWED_CHARS}` + " and simple functions, got: " + value);
|
|
23
|
+
return SafeStyle.INNOCUOUS_STRING;
|
|
24
|
+
} else if (COMMENT_RE.test(value)) {
|
|
25
|
+
fail(`String value disallows comments, got: ${value}`);
|
|
26
|
+
return SafeStyle.INNOCUOUS_STRING;
|
|
27
|
+
} else if (!hasBalancedQuotes(value)) {
|
|
28
|
+
fail(`String value requires balanced quotes, got: ${value}`);
|
|
29
|
+
return SafeStyle.INNOCUOUS_STRING;
|
|
30
|
+
} else if (!hasBalancedSquareBrackets(value)) {
|
|
31
|
+
fail("String value requires balanced square brackets and one" + " identifier per pair of brackets, got: " + value);
|
|
32
|
+
return SafeStyle.INNOCUOUS_STRING;
|
|
33
|
+
}
|
|
34
|
+
return sanitizeUrl(value);
|
|
35
|
+
}
|
|
36
|
+
function hasBalancedQuotes(value) {
|
|
37
|
+
let outsideSingle = true;
|
|
38
|
+
let outsideDouble = true;
|
|
39
|
+
for (let i = 0; i < value.length; i++) {
|
|
40
|
+
const c = value.charAt(i);
|
|
41
|
+
if (c == "'" && outsideDouble) {
|
|
42
|
+
outsideSingle = !outsideSingle;
|
|
43
|
+
} else if (c == '"' && outsideSingle) {
|
|
44
|
+
outsideDouble = !outsideDouble;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return outsideSingle && outsideDouble;
|
|
48
|
+
}
|
|
49
|
+
function hasBalancedSquareBrackets(value) {
|
|
50
|
+
let outside = true;
|
|
51
|
+
const tokenRe = /^[-_a-zA-Z0-9]$/;
|
|
52
|
+
for (let i = 0; i < value.length; i++) {
|
|
53
|
+
const c = value.charAt(i);
|
|
54
|
+
if (c == "]") {
|
|
55
|
+
if (outside) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
outside = true;
|
|
59
|
+
} else if (c == "[") {
|
|
60
|
+
if (!outside) {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
outside = false;
|
|
64
|
+
} else if (!outside && !tokenRe.test(c)) {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return outside;
|
|
69
|
+
}
|
|
70
|
+
function sanitizeUrl(value) {
|
|
71
|
+
return value.replace(URL_RE, (match, before, url, after) => {
|
|
72
|
+
let quote = "";
|
|
73
|
+
url = url.replace(/^(['"])(.*)\1$/, (match, start, inside) => {
|
|
74
|
+
quote = start;
|
|
75
|
+
return inside;
|
|
76
|
+
});
|
|
77
|
+
const sanitized = SafeUrl.sanitize(url).getTypedStringValue();
|
|
78
|
+
return before + quote + sanitized + quote + after;
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
"use strict";
|
|
82
|
+
goog.module("goog.html.SafeStyle");
|
|
83
|
+
goog.module.declareLegacyNamespace();
|
|
84
|
+
const Const = goog.require("goog.string.Const");
|
|
85
|
+
const SafeUrl = goog.require("goog.html.SafeUrl");
|
|
86
|
+
const TypedString = goog.require("goog.string.TypedString");
|
|
87
|
+
const {AssertionError, assert, fail} = goog.require("goog.asserts");
|
|
88
|
+
const {contains, endsWith} = goog.require("goog.string.internal");
|
|
89
|
+
const CONSTRUCTOR_TOKEN_PRIVATE = {};
|
|
90
|
+
class SafeStyle {
|
|
91
|
+
constructor(value, token) {
|
|
92
|
+
this.privateDoNotAccessOrElseSafeStyleWrappedValue_ = token === CONSTRUCTOR_TOKEN_PRIVATE ? value : "";
|
|
93
|
+
this.implementsGoogStringTypedString = true;
|
|
94
|
+
}
|
|
95
|
+
static fromConstant(style) {
|
|
96
|
+
const styleString = Const.unwrap(style);
|
|
97
|
+
if (styleString.length === 0) {
|
|
98
|
+
return SafeStyle.EMPTY;
|
|
99
|
+
}
|
|
100
|
+
assert(endsWith(styleString, ";"), `Last character of style string is not ';': ${styleString}`);
|
|
101
|
+
assert(contains(styleString, ":"), "Style string must contain at least one ':', to " + 'specify a "name: value" pair: ' + styleString);
|
|
102
|
+
return SafeStyle.createSafeStyleSecurityPrivateDoNotAccessOrElse(styleString);
|
|
103
|
+
}
|
|
104
|
+
getTypedStringValue() {
|
|
105
|
+
return this.privateDoNotAccessOrElseSafeStyleWrappedValue_;
|
|
106
|
+
}
|
|
107
|
+
toString() {
|
|
108
|
+
return this.privateDoNotAccessOrElseSafeStyleWrappedValue_.toString();
|
|
109
|
+
}
|
|
110
|
+
static unwrap(safeStyle) {
|
|
111
|
+
if (safeStyle instanceof SafeStyle && safeStyle.constructor === SafeStyle) {
|
|
112
|
+
return safeStyle.privateDoNotAccessOrElseSafeStyleWrappedValue_;
|
|
113
|
+
} else {
|
|
114
|
+
fail(`expected object of type SafeStyle, got '${safeStyle}` + "' of type " + goog.typeOf(safeStyle));
|
|
115
|
+
return "type_error:SafeStyle";
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
static createSafeStyleSecurityPrivateDoNotAccessOrElse(style) {
|
|
119
|
+
return new SafeStyle(style, CONSTRUCTOR_TOKEN_PRIVATE);
|
|
120
|
+
}
|
|
121
|
+
static create(map) {
|
|
122
|
+
let style = "";
|
|
123
|
+
for (let name in map) {
|
|
124
|
+
if (Object.prototype.hasOwnProperty.call(map, name)) {
|
|
125
|
+
if (!/^[-_a-zA-Z0-9]+$/.test(name)) {
|
|
126
|
+
throw new Error(`Name allows only [-_a-zA-Z0-9], got: ${name}`);
|
|
127
|
+
}
|
|
128
|
+
let value = map[name];
|
|
129
|
+
if (value == null) {
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
if (Array.isArray(value)) {
|
|
133
|
+
value = value.map(sanitizePropertyValue).join(" ");
|
|
134
|
+
} else {
|
|
135
|
+
value = sanitizePropertyValue(value);
|
|
136
|
+
}
|
|
137
|
+
style = style + `${name}:${value};`;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
if (!style) {
|
|
141
|
+
return SafeStyle.EMPTY;
|
|
142
|
+
}
|
|
143
|
+
return SafeStyle.createSafeStyleSecurityPrivateDoNotAccessOrElse(style);
|
|
144
|
+
}
|
|
145
|
+
static concat(var_args) {
|
|
146
|
+
let style = "";
|
|
147
|
+
const addArgument = argument => {
|
|
148
|
+
if (Array.isArray(argument)) {
|
|
149
|
+
argument.forEach(addArgument);
|
|
150
|
+
} else {
|
|
151
|
+
style = style + SafeStyle.unwrap(argument);
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
Array.prototype.forEach.call(arguments, addArgument);
|
|
155
|
+
if (!style) {
|
|
156
|
+
return SafeStyle.EMPTY;
|
|
157
|
+
}
|
|
158
|
+
return SafeStyle.createSafeStyleSecurityPrivateDoNotAccessOrElse(style);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
SafeStyle.EMPTY = SafeStyle.createSafeStyleSecurityPrivateDoNotAccessOrElse("");
|
|
162
|
+
SafeStyle.INNOCUOUS_STRING = "zClosurez";
|
|
163
|
+
SafeStyle.PropertyValue;
|
|
164
|
+
SafeStyle.PropertyMap;
|
|
165
|
+
const VALUE_ALLOWED_CHARS = "[-+,.\"'%_!#/ a-zA-Z0-9\\[\\]]";
|
|
166
|
+
const VALUE_RE = new RegExp(`^${VALUE_ALLOWED_CHARS}+\$`);
|
|
167
|
+
const URL_RE = new RegExp("\\b(url\\([ \t\n]*)(" + "'[ -\x26(-\\[\\]-~]*'" + '|"[ !#-\\[\\]-~]*"' + "|[!#-\x26*-\\[\\]-~]*" + ")([ \t\n]*\\))", "g");
|
|
168
|
+
const ALLOWED_FUNCTIONS = ["calc", "cubic-bezier", "fit-content", "hsl", "hsla", "linear-gradient", "matrix", "minmax", "radial-gradient", "repeat", "rgb", "rgba", "(rotate|scale|translate)(X|Y|Z|3d)?", "steps", "var"];
|
|
169
|
+
const FUNCTIONS_RE = new RegExp("\\b(" + ALLOWED_FUNCTIONS.join("|") + ")" + "\\([-+*/0-9a-zA-Z.%#\\[\\], ]+\\)", "g");
|
|
170
|
+
const COMMENT_RE = /\/\*/;
|
|
171
|
+
exports = SafeStyle;
|
|
172
|
+
return exports;
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
//# sourceMappingURL=goog.html.safestyle.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version":3,
|
|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AAUjE,SAAV;AA3jBA,SAAA,OAAA;AAAA,CAAA,CAAA;;",
|
|
6
|
+
"sources":["goog/html/safestyle.js"],
|
|
7
|
+
"sourcesContent":["/**\n * @license\n * Copyright The Closure Library Authors.\n * SPDX-License-Identifier: Apache-2.0\n */\n\n/**\n * @fileoverview The SafeStyle type and its builders.\n *\n * TODO(xtof): Link to document stating type contract.\n */\n\ngoog.module('goog.html.SafeStyle');\ngoog.module.declareLegacyNamespace();\n\nconst Const = goog.require('goog.string.Const');\nconst SafeUrl = goog.require('goog.html.SafeUrl');\nconst TypedString = goog.require('goog.string.TypedString');\nconst {AssertionError, assert, fail} = goog.require('goog.asserts');\nconst {contains, endsWith} = goog.require('goog.string.internal');\n\n/**\n * Token used to ensure that object is created only from this file. No code\n * outside of this file can access this token.\n * @type {!Object}\n * @const\n */\nconst CONSTRUCTOR_TOKEN_PRIVATE = {};\n\n/**\n * A string-like object which represents a sequence of CSS declarations\n * (`propertyName1: propertyvalue1; propertyName2: propertyValue2; ...`)\n * and that carries the security type contract that its value, as a string,\n * will not cause untrusted script execution (XSS) when evaluated as CSS in a\n * browser.\n *\n * Instances of this type must be created via the factory methods\n * (`SafeStyle.create` or `SafeStyle.fromConstant`)\n * and not by invoking its constructor. The constructor intentionally takes an\n * extra parameter that cannot be constructed outside of this file and the type\n * is immutable; hence only a default instance corresponding to the empty string\n * can be obtained via constructor invocation.\n *\n * SafeStyle's string representation can safely be:\n * <ul>\n * <li>Interpolated as the content of a *quoted* HTML style attribute.\n * However, the SafeStyle string *must be HTML-attribute-escaped* before\n * interpolation.\n * <li>Interpolated as the content of a {}-wrapped block within a stylesheet.\n * '<' characters in the SafeStyle string *must be CSS-escaped* before\n * interpolation. The SafeStyle string is also guaranteed not to be able\n * to introduce new properties or elide existing ones.\n * <li>Interpolated as the content of a {}-wrapped block within an HTML\n * <style> element. '<' characters in the SafeStyle string\n * *must be CSS-escaped* before interpolation.\n * <li>Assigned to the style property of a DOM node. The SafeStyle string\n * should not be escaped before being assigned to the property.\n * </ul>\n *\n * A SafeStyle may never contain literal angle brackets. Otherwise, it could\n * be unsafe to place a SafeStyle into a <style> tag (where it can't\n * be HTML escaped). For example, if the SafeStyle containing\n * `font: 'foo <style/><script>evil</script>'` were\n * interpolated within a <style> tag, this would then break out of the\n * style context into HTML.\n *\n * A SafeStyle may contain literal single or double quotes, and as such the\n * entire style string must be escaped when used in a style attribute (if\n * this were not the case, the string could contain a matching quote that\n * would escape from the style attribute).\n *\n * Values of this type must be composable, i.e. for any two values\n * `style1` and `style2` of this type,\n * `SafeStyle.unwrap(style1) +\n * SafeStyle.unwrap(style2)` must itself be a value that satisfies\n * the SafeStyle type constraint. This requirement implies that for any value\n * `style` of this type, `SafeStyle.unwrap(style)` must\n * not end in a \"property value\" or \"property name\" context. For example,\n * a value of `background:url(\"` or `font-` would not satisfy the\n * SafeStyle contract. This is because concatenating such strings with a\n * second value that itself does not contain unsafe CSS can result in an\n * overall string that does. For example, if `javascript:evil())\"` is\n * appended to `background:url(\"}, the resulting string may result in\n * the execution of a malicious script.\n *\n * TODO(mlourenco): Consider whether we should implement UTF-8 interchange\n * validity checks and blacklisting of newlines (including Unicode ones) and\n * other whitespace characters (\\t, \\f). Document here if so and also update\n * SafeStyle.fromConstant().\n *\n * The following example values comply with this type's contract:\n * <ul>\n * <li><pre>width: 1em;</pre>\n * <li><pre>height:1em;</pre>\n * <li><pre>width: 1em;height: 1em;</pre>\n * <li><pre>background:url('http://url');</pre>\n * </ul>\n * In addition, the empty string is safe for use in a CSS attribute.\n *\n * The following example values do NOT comply with this type's contract:\n * <ul>\n * <li><pre>background: red</pre> (missing a trailing semi-colon)\n * <li><pre>background:</pre> (missing a value and a trailing semi-colon)\n * <li><pre>1em</pre> (missing an attribute name, which provides context for\n * the value)\n * </ul>\n *\n * @see SafeStyle#create\n * @see SafeStyle#fromConstant\n * @see http://www.w3.org/TR/css3-syntax/\n * @final\n * @struct\n * @implements {TypedString}\n */\nclass SafeStyle {\n /**\n * @param {string} value\n * @param {!Object} token package-internal implementation detail.\n */\n constructor(value, token) {\n /**\n * The contained value of this SafeStyle. The field has a purposely\n * ugly name to make (non-compiled) code that attempts to directly access\n * this field stand out.\n * @private {string}\n */\n this.privateDoNotAccessOrElseSafeStyleWrappedValue_ =\n (token === CONSTRUCTOR_TOKEN_PRIVATE) ? value : '';\n\n /**\n * @override\n * @const {boolean}\n */\n this.implementsGoogStringTypedString = true;\n }\n\n\n /**\n * Creates a SafeStyle object from a compile-time constant string.\n *\n * `style` should be in the format\n * `name: value; [name: value; ...]` and must not have any < or >\n * characters in it. This is so that SafeStyle's contract is preserved,\n * allowing the SafeStyle to correctly be interpreted as a sequence of CSS\n * declarations and without affecting the syntactic structure of any\n * surrounding CSS and HTML.\n *\n * This method performs basic sanity checks on the format of `style`\n * but does not constrain the format of `name` and `value`, except\n * for disallowing tag characters.\n *\n * @param {!Const} style A compile-time-constant string from which\n * to create a SafeStyle.\n * @return {!SafeStyle} A SafeStyle object initialized to\n * `style`.\n */\n static fromConstant(style) {\n const styleString = Const.unwrap(style);\n if (styleString.length === 0) {\n return SafeStyle.EMPTY;\n }\n assert(\n endsWith(styleString, ';'),\n `Last character of style string is not ';': ${styleString}`);\n assert(\n contains(styleString, ':'),\n 'Style string must contain at least one \\':\\', to ' +\n 'specify a \"name: value\" pair: ' + styleString);\n return SafeStyle.createSafeStyleSecurityPrivateDoNotAccessOrElse(\n styleString);\n };\n\n\n /**\n * Returns this SafeStyle's value as a string.\n *\n * IMPORTANT: In code where it is security relevant that an object's type is\n * indeed `SafeStyle`, use `SafeStyle.unwrap` instead of\n * this method. If in doubt, assume that it's security relevant. In\n * particular, note that goog.html functions which return a goog.html type do\n * not guarantee the returned instance is of the right type. For example:\n *\n * <pre>\n * var fakeSafeHtml = new String('fake');\n * fakeSafeHtml.__proto__ = goog.html.SafeHtml.prototype;\n * var newSafeHtml = goog.html.SafeHtml.htmlEscape(fakeSafeHtml);\n * // newSafeHtml is just an alias for fakeSafeHtml, it's passed through by\n * // goog.html.SafeHtml.htmlEscape() as fakeSafeHtml\n * // instanceof goog.html.SafeHtml.\n * </pre>\n *\n * @return {string}\n * @see SafeStyle#unwrap\n * @override\n */\n getTypedStringValue() {\n return this.privateDoNotAccessOrElseSafeStyleWrappedValue_;\n }\n\n\n /**\n * Returns a string-representation of this value.\n *\n * To obtain the actual string value wrapped in a SafeStyle, use\n * `SafeStyle.unwrap`.\n *\n * @return {string}\n * @see SafeStyle#unwrap\n * @override\n */\n toString() {\n return this.privateDoNotAccessOrElseSafeStyleWrappedValue_.toString();\n }\n\n\n /**\n * Performs a runtime check that the provided object is indeed a\n * SafeStyle object, and returns its value.\n *\n * @param {!SafeStyle} safeStyle The object to extract from.\n * @return {string} The safeStyle object's contained string, unless\n * the run-time type check fails. In that case, `unwrap` returns an\n * innocuous string, or, if assertions are enabled, throws\n * `AssertionError`.\n */\n static unwrap(safeStyle) {\n // Perform additional Run-time type-checking to ensure that\n // safeStyle is indeed an instance of the expected type. This\n // provides some additional protection against security bugs due to\n // application code that disables type checks.\n // Specifically, the following checks are performed:\n // 1. The object is an instance of the expected type.\n // 2. The object is not an instance of a subclass.\n if (safeStyle instanceof SafeStyle && safeStyle.constructor === SafeStyle) {\n return safeStyle.privateDoNotAccessOrElseSafeStyleWrappedValue_;\n } else {\n fail(\n `expected object of type SafeStyle, got '${safeStyle}` +\n '\\' of type ' + goog.typeOf(safeStyle));\n return 'type_error:SafeStyle';\n }\n }\n\n\n /**\n * Package-internal utility method to create SafeStyle instances.\n *\n * @param {string} style The string to initialize the SafeStyle object with.\n * @return {!SafeStyle} The initialized SafeStyle object.\n * @package\n */\n static createSafeStyleSecurityPrivateDoNotAccessOrElse(style) {\n return new SafeStyle(style, CONSTRUCTOR_TOKEN_PRIVATE);\n }\n\n /**\n * Creates a new SafeStyle object from the properties specified in the map.\n * @param {!SafeStyle.PropertyMap} map Mapping of property names to\n * their values, for example {'margin': '1px'}. Names must consist of\n * [-_a-zA-Z0-9]. Values might be strings consisting of\n * [-,.'\"%_!# a-zA-Z0-9[\\]], where \", ', and [] must be properly balanced.\n * We also allow simple functions like rgb() and url() which sanitizes its\n * contents. Other values must be wrapped in Const. URLs might\n * be passed as SafeUrl which will be wrapped into url(\"\"). We\n * also support array whose elements are joined with ' '. Null value\n * causes skipping the property.\n * @return {!SafeStyle}\n * @throws {!Error} If invalid name is provided.\n * @throws {!AssertionError} If invalid value is provided. With\n * disabled assertions, invalid value is replaced by\n * SafeStyle.INNOCUOUS_STRING.\n */\n static create(map) {\n let style = '';\n for (let name in map) {\n // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty#Using_hasOwnProperty_as_a_property_name\n if (Object.prototype.hasOwnProperty.call(map, name)) {\n if (!/^[-_a-zA-Z0-9]+$/.test(name)) {\n throw new Error(`Name allows only [-_a-zA-Z0-9], got: ${name}`);\n }\n let value = map[name];\n if (value == null) {\n continue;\n }\n if (Array.isArray(value)) {\n value = value.map(sanitizePropertyValue).join(' ');\n } else {\n value = sanitizePropertyValue(value);\n }\n style += `${name}:${value};`;\n }\n }\n if (!style) {\n return SafeStyle.EMPTY;\n }\n return SafeStyle.createSafeStyleSecurityPrivateDoNotAccessOrElse(style);\n };\n\n /**\n * Creates a new SafeStyle object by concatenating the values.\n * @param {...(!SafeStyle|!Array<!SafeStyle>)} var_args\n * SafeStyles to concatenate.\n * @return {!SafeStyle}\n */\n static concat(var_args) {\n let style = '';\n\n /**\n * @param {!SafeStyle|!Array<!SafeStyle>} argument\n */\n const addArgument = argument => {\n if (Array.isArray(argument)) {\n argument.forEach(addArgument);\n } else {\n style += SafeStyle.unwrap(argument);\n }\n };\n\n Array.prototype.forEach.call(arguments, addArgument);\n if (!style) {\n return SafeStyle.EMPTY;\n }\n return SafeStyle.createSafeStyleSecurityPrivateDoNotAccessOrElse(style);\n };\n}\n\n/**\n * A SafeStyle instance corresponding to the empty string.\n * @const {!SafeStyle}\n */\nSafeStyle.EMPTY = SafeStyle.createSafeStyleSecurityPrivateDoNotAccessOrElse('');\n\n\n/**\n * The innocuous string generated by SafeStyle.create when passed\n * an unsafe value.\n * @const {string}\n */\nSafeStyle.INNOCUOUS_STRING = 'zClosurez';\n\n\n/**\n * A single property value.\n * @typedef {string|!Const|!SafeUrl}\n */\nSafeStyle.PropertyValue;\n\n\n/**\n * Mapping of property names to their values.\n * We don't support numbers even though some values might be numbers (e.g.\n * line-height or 0 for any length). The reason is that most numeric values need\n * units (e.g. '1px') and allowing numbers could cause users forgetting about\n * them.\n * @typedef {!Object<string, ?SafeStyle.PropertyValue|\n * ?Array<!SafeStyle.PropertyValue>>}\n */\nSafeStyle.PropertyMap;\n\n\n\n/**\n * Checks and converts value to string.\n * @param {!SafeStyle.PropertyValue} value\n * @return {string}\n */\nfunction sanitizePropertyValue(value) {\n if (value instanceof SafeUrl) {\n const url = SafeUrl.unwrap(value);\n return 'url(\"' + url.replace(/</g, '%3c').replace(/[\\\\\"]/g, '\\\\$&') + '\")';\n }\n const result = value instanceof Const ?\n Const.unwrap(value) :\n sanitizePropertyValueString(String(value));\n // These characters can be used to change context and we don't want that even\n // with const values.\n if (/[{;}]/.test(result)) {\n throw new AssertionError('Value does not allow [{;}], got: %s.', [result]);\n }\n return result;\n}\n\n\n/**\n * Checks string value.\n * @param {string} value\n * @return {string}\n */\nfunction sanitizePropertyValueString(value) {\n // Some CSS property values permit nested functions. We allow one level of\n // nesting, and all nested functions must also be in the FUNCTIONS_RE_ list.\n const valueWithoutFunctions = value.replace(FUNCTIONS_RE, '$1')\n .replace(FUNCTIONS_RE, '$1')\n .replace(URL_RE, 'url');\n if (!VALUE_RE.test(valueWithoutFunctions)) {\n fail(\n `String value allows only ${VALUE_ALLOWED_CHARS}` +\n ' and simple functions, got: ' + value);\n return SafeStyle.INNOCUOUS_STRING;\n } else if (COMMENT_RE.test(value)) {\n fail(`String value disallows comments, got: ${value}`);\n return SafeStyle.INNOCUOUS_STRING;\n } else if (!hasBalancedQuotes(value)) {\n fail(`String value requires balanced quotes, got: ${value}`);\n return SafeStyle.INNOCUOUS_STRING;\n } else if (!hasBalancedSquareBrackets(value)) {\n fail(\n 'String value requires balanced square brackets and one' +\n ' identifier per pair of brackets, got: ' + value);\n return SafeStyle.INNOCUOUS_STRING;\n }\n return sanitizeUrl(value);\n}\n\n\n/**\n * Checks that quotes (\" and ') are properly balanced inside a string. Assumes\n * that neither escape (\\) nor any other character that could result in\n * breaking out of a string parsing context are allowed;\n * see http://www.w3.org/TR/css3-syntax/#string-token-diagram.\n * @param {string} value Untrusted CSS property value.\n * @return {boolean} True if property value is safe with respect to quote\n * balancedness.\n */\nfunction hasBalancedQuotes(value) {\n let outsideSingle = true;\n let outsideDouble = true;\n for (let i = 0; i < value.length; i++) {\n const c = value.charAt(i);\n if (c == '\\'' && outsideDouble) {\n outsideSingle = !outsideSingle;\n } else if (c == '\"' && outsideSingle) {\n outsideDouble = !outsideDouble;\n }\n }\n return outsideSingle && outsideDouble;\n}\n\n\n/**\n * Checks that square brackets ([ and ]) are properly balanced inside a string,\n * and that the content in the square brackets is one ident-token;\n * see https://www.w3.org/TR/css-syntax-3/#ident-token-diagram.\n * For practicality, and in line with other restrictions posed on SafeStyle\n * strings, we restrict the character set allowable in the ident-token to\n * [-_a-zA-Z0-9].\n * @param {string} value Untrusted CSS property value.\n * @return {boolean} True if property value is safe with respect to square\n * bracket balancedness.\n */\nfunction hasBalancedSquareBrackets(value) {\n let outside = true;\n const tokenRe = /^[-_a-zA-Z0-9]$/;\n for (let i = 0; i < value.length; i++) {\n const c = value.charAt(i);\n if (c == ']') {\n if (outside) return false; // Unbalanced ].\n outside = true;\n } else if (c == '[') {\n if (!outside) return false; // No nesting.\n outside = false;\n } else if (!outside && !tokenRe.test(c)) {\n return false;\n }\n }\n return outside;\n}\n\n\n/**\n * Characters allowed in VALUE_RE.\n * @type {string}\n */\nconst VALUE_ALLOWED_CHARS = '[-+,.\"\\'%_!#/ a-zA-Z0-9\\\\[\\\\]]';\n\n\n/**\n * Regular expression for safe values.\n * Quotes (\" and ') are allowed, but a check must be done elsewhere to ensure\n * they're balanced.\n * Square brackets ([ and ]) are allowed, but a check must be done elsewhere\n * to ensure they're balanced. The content inside a pair of square brackets must\n * be one alphanumeric identifier.\n * ',' allows multiple values to be assigned to the same property\n * (e.g. background-attachment or font-family) and hence could allow\n * multiple values to get injected, but that should pose no risk of XSS.\n * The expression checks only for XSS safety, not for CSS validity.\n * @const {!RegExp}\n */\nconst VALUE_RE = new RegExp(`^${VALUE_ALLOWED_CHARS}+\\$`);\n\n\n/**\n * Regular expression for url(). We support URLs allowed by\n * https://www.w3.org/TR/css-syntax-3/#url-token-diagram without using escape\n * sequences. Use percent-encoding if you need to use special characters like\n * backslash.\n * @const {!RegExp}\n */\nconst URL_RE = new RegExp(\n '\\\\b(url\\\\([ \\t\\n]*)(' +\n '\\'[ -&(-\\\\[\\\\]-~]*\\'' + // Printable characters except ' and \\.\n '|\"[ !#-\\\\[\\\\]-~]*\"' + // Printable characters except \" and \\.\n '|[!#-&*-\\\\[\\\\]-~]*' + // Printable characters except [ \"'()\\\\].\n ')([ \\t\\n]*\\\\))',\n 'g');\n\n/**\n * Names of functions allowed in FUNCTIONS_RE.\n * @const {!Array<string>}\n */\nconst ALLOWED_FUNCTIONS = [\n 'calc',\n 'cubic-bezier',\n 'fit-content',\n 'hsl',\n 'hsla',\n 'linear-gradient',\n 'matrix',\n 'minmax',\n 'radial-gradient',\n 'repeat',\n 'rgb',\n 'rgba',\n '(rotate|scale|translate)(X|Y|Z|3d)?',\n 'steps',\n 'var',\n];\n\n\n/**\n * Regular expression for simple functions.\n * @const {!RegExp}\n */\nconst FUNCTIONS_RE = new RegExp(\n '\\\\b(' + ALLOWED_FUNCTIONS.join('|') + ')' +\n '\\\\([-+*/0-9a-zA-Z.%#\\\\[\\\\], ]+\\\\)',\n 'g');\n\n\n/**\n * Regular expression for comments. These are disallowed in CSS property values.\n * @const {!RegExp}\n */\nconst COMMENT_RE = /\\/\\*/;\n\n\n/**\n * Sanitize URLs inside url().\n * NOTE: We could also consider using CSS.escape once that's available in the\n * browsers. However, loosely matching URL e.g. with url\\(.*\\) and then escaping\n * the contents would result in a slightly different language than CSS leading\n * to confusion of users. E.g. url(\")\") is valid in CSS but it would be invalid\n * as seen by our parser. On the other hand, url(\\) is invalid in CSS but our\n * parser would be fine with it.\n * @param {string} value Untrusted CSS property value.\n * @return {string}\n */\nfunction sanitizeUrl(value) {\n return value.replace(URL_RE, (match, before, url, after) => {\n let quote = '';\n url = url.replace(/^(['\"])(.*)\\1$/, (match, start, inside) => {\n quote = start;\n return inside;\n });\n const sanitized = SafeUrl.sanitize(url).getTypedStringValue();\n return before + quote + sanitized + quote + after;\n });\n}\n\n\nexports = SafeStyle;\n"],
|
|
8
|
+
"names":["sanitizePropertyValue","value","SafeUrl","url","unwrap","replace","result","Const","sanitizePropertyValueString","String","test","AssertionError","valueWithoutFunctions","FUNCTIONS_RE","URL_RE","VALUE_RE","fail","VALUE_ALLOWED_CHARS","SafeStyle","INNOCUOUS_STRING","COMMENT_RE","hasBalancedQuotes","hasBalancedSquareBrackets","sanitizeUrl","outsideSingle","outsideDouble","i","length","c","charAt","outside","tokenRe","match","before","after","quote","start","inside","sanitized","sanitize","getTypedStringValue","goog","module","declareLegacyNamespace","require","TypedString","assert","contains","endsWith","CONSTRUCTOR_TOKEN_PRIVATE","constructor","token","privateDoNotAccessOrElseSafeStyleWrappedValue_","implementsGoogStringTypedString","fromConstant","style","styleString","EMPTY","createSafeStyleSecurityPrivateDoNotAccessOrElse","toString","safeStyle","typeOf","create","map","name","Object","prototype","hasOwnProperty","call","Error","Array","isArray","join","concat","var_args","addArgument","argument","forEach","arguments","PropertyValue","PropertyMap","RegExp","ALLOWED_FUNCTIONS","exports"]
|
|
9
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import "./cljs_env.js";
|
|
2
|
+
import "./goog.string.const.js";
|
|
3
|
+
import "./goog.html.safestyle.js";
|
|
4
|
+
import "./goog.string.typedstring.js";
|
|
5
|
+
import "./goog.object.object.js";
|
|
6
|
+
import "./goog.asserts.asserts.js";
|
|
7
|
+
import "./goog.string.internal.js";
|
|
8
|
+
goog.loadModule(function(exports) {
|
|
9
|
+
"use strict";
|
|
10
|
+
goog.module("goog.html.SafeStyleSheet");
|
|
11
|
+
goog.module.declareLegacyNamespace();
|
|
12
|
+
const Const = goog.require("goog.string.Const");
|
|
13
|
+
const SafeStyle = goog.require("goog.html.SafeStyle");
|
|
14
|
+
const TypedString = goog.require("goog.string.TypedString");
|
|
15
|
+
const googObject = goog.require("goog.object");
|
|
16
|
+
const {assert, fail} = goog.require("goog.asserts");
|
|
17
|
+
const {contains} = goog.require("goog.string.internal");
|
|
18
|
+
const CONSTRUCTOR_TOKEN_PRIVATE = {};
|
|
19
|
+
class SafeStyleSheet {
|
|
20
|
+
constructor(value, token) {
|
|
21
|
+
this.privateDoNotAccessOrElseSafeStyleSheetWrappedValue_ = token === CONSTRUCTOR_TOKEN_PRIVATE ? value : "";
|
|
22
|
+
this.implementsGoogStringTypedString = true;
|
|
23
|
+
}
|
|
24
|
+
toString() {
|
|
25
|
+
return this.privateDoNotAccessOrElseSafeStyleSheetWrappedValue_.toString();
|
|
26
|
+
}
|
|
27
|
+
static createRule(selector, style) {
|
|
28
|
+
if (contains(selector, "\x3c")) {
|
|
29
|
+
throw new Error(`Selector does not allow '<', got: ${selector}`);
|
|
30
|
+
}
|
|
31
|
+
const selectorToCheck = selector.replace(/('|")((?!\1)[^\r\n\f\\]|\\[\s\S])*\1/g, "");
|
|
32
|
+
if (!/^[-_a-zA-Z0-9#.:* ,>+~[\]()=^$|]+$/.test(selectorToCheck)) {
|
|
33
|
+
throw new Error("Selector allows only [-_a-zA-Z0-9#.:* ,\x3e+~[\\]()\x3d^$|] and " + "strings, got: " + selector);
|
|
34
|
+
}
|
|
35
|
+
if (!SafeStyleSheet.hasBalancedBrackets_(selectorToCheck)) {
|
|
36
|
+
throw new Error("() and [] in selector must be balanced, got: " + selector);
|
|
37
|
+
}
|
|
38
|
+
if (!(style instanceof SafeStyle)) {
|
|
39
|
+
style = SafeStyle.create(style);
|
|
40
|
+
}
|
|
41
|
+
const styleSheet = `${selector}{` + SafeStyle.unwrap(style).replace(/</g, "\\3C ") + "}";
|
|
42
|
+
return SafeStyleSheet.createSafeStyleSheetSecurityPrivateDoNotAccessOrElse(styleSheet);
|
|
43
|
+
}
|
|
44
|
+
static hasBalancedBrackets_(s) {
|
|
45
|
+
const brackets = {"(":")", "[":"]"};
|
|
46
|
+
const expectedBrackets = [];
|
|
47
|
+
for (let i = 0; i < s.length; i++) {
|
|
48
|
+
const ch = s[i];
|
|
49
|
+
if (brackets[ch]) {
|
|
50
|
+
expectedBrackets.push(brackets[ch]);
|
|
51
|
+
} else if (googObject.contains(brackets, ch)) {
|
|
52
|
+
if (expectedBrackets.pop() != ch) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return expectedBrackets.length == 0;
|
|
58
|
+
}
|
|
59
|
+
static concat(var_args) {
|
|
60
|
+
let result = "";
|
|
61
|
+
const addArgument = argument => {
|
|
62
|
+
if (Array.isArray(argument)) {
|
|
63
|
+
argument.forEach(addArgument);
|
|
64
|
+
} else {
|
|
65
|
+
result = result + SafeStyleSheet.unwrap(argument);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
Array.prototype.forEach.call(arguments, addArgument);
|
|
69
|
+
return SafeStyleSheet.createSafeStyleSheetSecurityPrivateDoNotAccessOrElse(result);
|
|
70
|
+
}
|
|
71
|
+
static fromConstant(styleSheet) {
|
|
72
|
+
const styleSheetString = Const.unwrap(styleSheet);
|
|
73
|
+
if (styleSheetString.length === 0) {
|
|
74
|
+
return SafeStyleSheet.EMPTY;
|
|
75
|
+
}
|
|
76
|
+
assert(!contains(styleSheetString, "\x3c"), `Forbidden '<' character in style sheet string: ${styleSheetString}`);
|
|
77
|
+
return SafeStyleSheet.createSafeStyleSheetSecurityPrivateDoNotAccessOrElse(styleSheetString);
|
|
78
|
+
}
|
|
79
|
+
getTypedStringValue() {
|
|
80
|
+
return this.privateDoNotAccessOrElseSafeStyleSheetWrappedValue_;
|
|
81
|
+
}
|
|
82
|
+
static unwrap(safeStyleSheet) {
|
|
83
|
+
if (safeStyleSheet instanceof SafeStyleSheet && safeStyleSheet.constructor === SafeStyleSheet) {
|
|
84
|
+
return safeStyleSheet.privateDoNotAccessOrElseSafeStyleSheetWrappedValue_;
|
|
85
|
+
} else {
|
|
86
|
+
fail("expected object of type SafeStyleSheet, got '" + safeStyleSheet + "' of type " + goog.typeOf(safeStyleSheet));
|
|
87
|
+
return "type_error:SafeStyleSheet";
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
static createSafeStyleSheetSecurityPrivateDoNotAccessOrElse(styleSheet) {
|
|
91
|
+
return new SafeStyleSheet(styleSheet, CONSTRUCTOR_TOKEN_PRIVATE);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
SafeStyleSheet.EMPTY = SafeStyleSheet.createSafeStyleSheetSecurityPrivateDoNotAccessOrElse("");
|
|
95
|
+
exports = SafeStyleSheet;
|
|
96
|
+
return exports;
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
//# sourceMappingURL=goog.html.safestylesheet.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version":3,
|
|
3
|
+
"file":"goog.html.safestylesheet.js",
|
|
4
|
+
"lineCount":91,
|
|
5
|
+
"mappings":"AAAA,IAAA,CAAA,UAAA,CAAA,QAAA,CAAA,OAAA,CAAA;AAAA,cAAA;AAYAA,MAAKC,CAAAA,MAAL,CAAY,0BAAZ,CAAA;AACAD,MAAKC,CAAAA,MAAOC,CAAAA,sBAAZ,EAAA;AAEA,QAAMC,QAAQH,IAAKI,CAAAA,OAAL,CAAa,mBAAb,CAAd;AACA,QAAMC,YAAYL,IAAKI,CAAAA,OAAL,CA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B,cAAekB,CAAAA,oDAAf,CACHW,MADG,CAAP;AAhBsB;AA+BjBS,uBAAY,CAACtB,UAAD,CAAa;AAC9B,YAAMuB,mBAAmBhD,KAAM0B,CAAAA,MAAN,CAAaD,UAAb,CAAzB;AACA,UAAIuB,gBAAiBhB,CAAAA,MAArB,KAAgC,CAAhC;AACE,eAAOvB,cAAewC,CAAAA,KAAtB;AADF;AAKA5C,YAAA,CACI,CAACE,QAAA,CAASyC,gBAAT,EAA2B,MAA3B,CADL,EAEK,kDAAiDA,gBAAjD,EAFL,CAAA;AAGA,aAAOvC,cAAekB,CAAAA,oDAAf,CACHqB,gBADG,CAAP;AAV8B;AAmChCE,uBAAmB,EAAG;AACpB,aAAO,IAAKrC,CAAAA,mDAAZ;AADoB;AAcfa,iBAAM,CAACyB,cAAD,CAAiB;AAQ5B,UAAIA,cAAJ,YAA8B1C,cAA9B,IACI0C,cAAezC,CAAAA,WADnB,KACmCD,cADnC;AAEE,eAAO0C,cAAetC,CAAAA,mDAAtB;AAFF,YAGO;AACLP,YAAA,CACI,+CADJ,GACuD6C,cADvD,GAEI,YAFJ,GAEoBtD,IAAKuD,CAAAA,MAAL,CAAYD,cAAZ,CAFpB,CAAA;AAGA,eAAO,2BAAP;AAJK;AAXqB;AA2BvBxB,+DAAoD,CAACF,UAAD,CAAa;AACtE,aAAO,IAAIhB,cAAJ,CAAmBgB,UAAnB,EAA+BjB,yBAA/B,CAAP;AADsE;AArN1E;AA8NAC,gBAAewC,CAAAA,KAAf,GACIxC,cAAekB,CAAAA,oDAAf,CAAoE,EAApE,CADJ;AAIA0B,SAAA,GAAU5C,cAAV;AAvSA,SAAA,OAAA;AAAA,CAAA,CAAA;;",
|
|
6
|
+
"sources":["goog/html/safestylesheet.js"],
|
|
7
|
+
"sourcesContent":["/**\n * @license\n * Copyright The Closure Library Authors.\n * SPDX-License-Identifier: Apache-2.0\n */\n\n/**\n * @fileoverview The SafeStyleSheet type and its builders.\n *\n * TODO(xtof): Link to document stating type contract.\n */\n\ngoog.module('goog.html.SafeStyleSheet');\ngoog.module.declareLegacyNamespace();\n\nconst Const = goog.require('goog.string.Const');\nconst SafeStyle = goog.require('goog.html.SafeStyle');\nconst TypedString = goog.require('goog.string.TypedString');\nconst googObject = goog.require('goog.object');\nconst {assert, fail} = goog.require('goog.asserts');\nconst {contains} = goog.require('goog.string.internal');\n\n/**\n * Token used to ensure that object is created only from this file. No code\n * outside of this file can access this token.\n * @const {!Object}\n */\nconst CONSTRUCTOR_TOKEN_PRIVATE = {};\n\n/**\n * A string-like object which represents a CSS style sheet and that carries the\n * security type contract that its value, as a string, will not cause untrusted\n * script execution (XSS) when evaluated as CSS in a browser.\n *\n * Instances of this type must be created via the factory method\n * `SafeStyleSheet.fromConstant` and not by invoking its constructor. The\n * constructor intentionally takes an extra parameter that cannot be constructed\n * outside of this file and the type is immutable; hence only a default instance\n * corresponding to the empty string can be obtained via constructor invocation.\n *\n * A SafeStyleSheet's string representation can safely be interpolated as the\n * content of a style element within HTML. The SafeStyleSheet string should\n * not be escaped before interpolation.\n *\n * Values of this type must be composable, i.e. for any two values\n * `styleSheet1` and `styleSheet2` of this type,\n * `SafeStyleSheet.unwrap(styleSheet1) + SafeStyleSheet.unwrap(styleSheet2)`\n * must itself be a value that satisfies the SafeStyleSheet type constraint.\n * This requirement implies that for any value `styleSheet` of this type,\n * `SafeStyleSheet.unwrap(styleSheet1)` must end in\n * \"beginning of rule\" context.\n *\n * A SafeStyleSheet can be constructed via security-reviewed unchecked\n * conversions. In this case producers of SafeStyleSheet must ensure themselves\n * that the SafeStyleSheet does not contain unsafe script. Note in particular\n * that `<` is dangerous, even when inside CSS strings, and so should\n * always be forbidden or CSS-escaped in user controlled input. For example, if\n * `</style><script>evil</script>\"` were interpolated\n * inside a CSS string, it would break out of the context of the original\n * style element and `evil` would execute. Also note that within an HTML\n * style (raw text) element, HTML character references, such as\n * `&lt;`, are not allowed. See\n * http://www.w3.org/TR/html5/scripting-1.html#restrictions-for-contents-of-script-elements\n * (similar considerations apply to the style element).\n *\n * @see SafeStyleSheet#fromConstant\n * @final\n * @implements {TypedString}\n */\nclass SafeStyleSheet {\n /**\n * @param {string} value\n * @param {!Object} token package-internal implementation detail.\n */\n constructor(value, token) {\n /**\n * The contained value of this SafeStyleSheet. The field has a purposely\n * ugly name to make (non-compiled) code that attempts to directly access\n * this field stand out.\n * @private {string}\n */\n this.privateDoNotAccessOrElseSafeStyleSheetWrappedValue_ =\n (token === CONSTRUCTOR_TOKEN_PRIVATE) ? value : '';\n\n /**\n * @override\n * @const\n */\n this.implementsGoogStringTypedString = true;\n }\n\n /**\n * Returns a string-representation of this value.\n *\n * To obtain the actual string value wrapped in a SafeStyleSheet, use\n * `SafeStyleSheet.unwrap`.\n *\n * @return {string}\n * @see SafeStyleSheet#unwrap\n * @override\n */\n toString() {\n return this.privateDoNotAccessOrElseSafeStyleSheetWrappedValue_.toString();\n }\n\n /**\n * Creates a style sheet consisting of one selector and one style definition.\n * Use {@link SafeStyleSheet.concat} to create longer style sheets.\n * This function doesn't support @import, @media and similar constructs.\n * @param {string} selector CSS selector, e.g. '#id' or 'tag .class, #id'. We\n * support CSS3 selectors: https://w3.org/TR/css3-selectors/#selectors.\n * @param {!SafeStyle.PropertyMap|!SafeStyle} style Style\n * definition associated with the selector.\n * @return {!SafeStyleSheet}\n * @throws {!Error} If invalid selector is provided.\n */\n static createRule(selector, style) {\n if (contains(selector, '<')) {\n throw new Error(`Selector does not allow '<', got: ${selector}`);\n }\n\n // Remove strings.\n const selectorToCheck =\n selector.replace(/('|\")((?!\\1)[^\\r\\n\\f\\\\]|\\\\[\\s\\S])*\\1/g, '');\n\n // Check characters allowed in CSS3 selectors.\n if (!/^[-_a-zA-Z0-9#.:* ,>+~[\\]()=^$|]+$/.test(selectorToCheck)) {\n throw new Error(\n 'Selector allows only [-_a-zA-Z0-9#.:* ,>+~[\\\\]()=^$|] and ' +\n 'strings, got: ' + selector);\n }\n\n // Check balanced () and [].\n if (!SafeStyleSheet.hasBalancedBrackets_(selectorToCheck)) {\n throw new Error(\n '() and [] in selector must be balanced, got: ' + selector);\n }\n\n if (!(style instanceof SafeStyle)) {\n style = SafeStyle.create(style);\n }\n const styleSheet =\n `${selector}{` + SafeStyle.unwrap(style).replace(/</g, '\\\\3C ') + '}';\n return SafeStyleSheet.createSafeStyleSheetSecurityPrivateDoNotAccessOrElse(\n styleSheet);\n }\n\n /**\n * Checks if a string has balanced () and [] brackets.\n * @param {string} s String to check.\n * @return {boolean}\n * @private\n */\n static hasBalancedBrackets_(s) {\n const brackets = {'(': ')', '[': ']'};\n const expectedBrackets = [];\n for (let i = 0; i < s.length; i++) {\n const ch = s[i];\n if (brackets[ch]) {\n expectedBrackets.push(brackets[ch]);\n } else if (googObject.contains(brackets, ch)) {\n if (expectedBrackets.pop() != ch) {\n return false;\n }\n }\n }\n return expectedBrackets.length == 0;\n }\n\n /**\n * Creates a new SafeStyleSheet object by concatenating values.\n * @param {...(!SafeStyleSheet|!Array<!SafeStyleSheet>)}\n * var_args Values to concatenate.\n * @return {!SafeStyleSheet}\n */\n static concat(var_args) {\n let result = '';\n\n /**\n * @param {!SafeStyleSheet|!Array<!SafeStyleSheet>}\n * argument\n */\n const addArgument = argument => {\n if (Array.isArray(argument)) {\n argument.forEach(addArgument);\n } else {\n result += SafeStyleSheet.unwrap(argument);\n }\n };\n\n Array.prototype.forEach.call(arguments, addArgument);\n return SafeStyleSheet.createSafeStyleSheetSecurityPrivateDoNotAccessOrElse(\n result);\n }\n\n /**\n * Creates a SafeStyleSheet object from a compile-time constant string.\n *\n * `styleSheet` must not have any < characters in it, so that\n * the syntactic structure of the surrounding HTML is not affected.\n *\n * @param {!Const} styleSheet A compile-time-constant string from\n * which to create a SafeStyleSheet.\n * @return {!SafeStyleSheet} A SafeStyleSheet object initialized to\n * `styleSheet`.\n */\n static fromConstant(styleSheet) {\n const styleSheetString = Const.unwrap(styleSheet);\n if (styleSheetString.length === 0) {\n return SafeStyleSheet.EMPTY;\n }\n // > is a valid character in CSS selectors and there's no strict need to\n // block it if we already block <.\n assert(\n !contains(styleSheetString, '<'),\n `Forbidden '<' character in style sheet string: ${styleSheetString}`);\n return SafeStyleSheet.createSafeStyleSheetSecurityPrivateDoNotAccessOrElse(\n styleSheetString);\n }\n\n /**\n * Returns this SafeStyleSheet's value as a string.\n *\n * IMPORTANT: In code where it is security relevant that an object's type is\n * indeed `SafeStyleSheet`, use `SafeStyleSheet.unwrap`\n * instead of this method. If in doubt, assume that it's security relevant. In\n * particular, note that goog.html functions which return a goog.html type do\n * not guarantee the returned instance is of the right type. For example:\n *\n * <pre>\n * var fakeSafeHtml = new String('fake');\n * fakeSafeHtml.__proto__ = goog.html.SafeHtml.prototype;\n * var newSafeHtml = goog.html.SafeHtml.htmlEscape(fakeSafeHtml);\n * // newSafeHtml is just an alias for fakeSafeHtml, it's passed through by\n * // goog.html.SafeHtml.htmlEscape() as fakeSafeHtml\n * // instanceof goog.html.SafeHtml.\n * </pre>\n *\n * @see SafeStyleSheet#unwrap\n * @override\n */\n getTypedStringValue() {\n return this.privateDoNotAccessOrElseSafeStyleSheetWrappedValue_;\n }\n\n /**\n * Performs a runtime check that the provided object is indeed a\n * SafeStyleSheet object, and returns its value.\n *\n * @param {!SafeStyleSheet} safeStyleSheet The object to extract from.\n * @return {string} The safeStyleSheet object's contained string, unless\n * the run-time type check fails. In that case, `unwrap` returns an\n * innocuous string, or, if assertions are enabled, throws\n * `asserts.AssertionError`.\n */\n static unwrap(safeStyleSheet) {\n // Perform additional Run-time type-checking to ensure that\n // safeStyleSheet is indeed an instance of the expected type. This\n // provides some additional protection against security bugs due to\n // application code that disables type checks.\n // Specifically, the following checks are performed:\n // 1. The object is an instance of the expected type.\n // 2. The object is not an instance of a subclass.\n if (safeStyleSheet instanceof SafeStyleSheet &&\n safeStyleSheet.constructor === SafeStyleSheet) {\n return safeStyleSheet.privateDoNotAccessOrElseSafeStyleSheetWrappedValue_;\n } else {\n fail(\n 'expected object of type SafeStyleSheet, got \\'' + safeStyleSheet +\n '\\' of type ' + goog.typeOf(safeStyleSheet));\n return 'type_error:SafeStyleSheet';\n }\n }\n\n /**\n * Package-internal utility method to create SafeStyleSheet instances.\n *\n * @param {string} styleSheet The string to initialize the SafeStyleSheet\n * object with.\n * @return {!SafeStyleSheet} The initialized SafeStyleSheet object.\n * @package\n */\n static createSafeStyleSheetSecurityPrivateDoNotAccessOrElse(styleSheet) {\n return new SafeStyleSheet(styleSheet, CONSTRUCTOR_TOKEN_PRIVATE);\n }\n}\n\n/**\n * A SafeStyleSheet instance corresponding to the empty string.\n * @const {!SafeStyleSheet}\n */\nSafeStyleSheet.EMPTY =\n SafeStyleSheet.createSafeStyleSheetSecurityPrivateDoNotAccessOrElse('');\n\n\nexports = SafeStyleSheet;\n"],
|
|
8
|
+
"names":["goog","module","declareLegacyNamespace","Const","require","SafeStyle","TypedString","googObject","assert","fail","contains","CONSTRUCTOR_TOKEN_PRIVATE","SafeStyleSheet","constructor","value","token","privateDoNotAccessOrElseSafeStyleSheetWrappedValue_","implementsGoogStringTypedString","toString","createRule","selector","style","Error","selectorToCheck","replace","test","hasBalancedBrackets_","create","styleSheet","unwrap","createSafeStyleSheetSecurityPrivateDoNotAccessOrElse","s","brackets","expectedBrackets","i","length","ch","push","pop","concat","var_args","result","addArgument","argument","Array","isArray","forEach","prototype","call","arguments","fromConstant","styleSheetString","EMPTY","getTypedStringValue","safeStyleSheet","typeOf","exports"]
|
|
9
|
+
}
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import "./cljs_env.js";
|
|
2
|
+
import "./goog.asserts.asserts.js";
|
|
3
|
+
import "./goog.fs.url.js";
|
|
4
|
+
import "./goog.html.trustedresourceurl.js";
|
|
5
|
+
import "./goog.string.const.js";
|
|
6
|
+
import "./goog.string.typedstring.js";
|
|
7
|
+
import "./goog.string.internal.js";
|
|
8
|
+
goog.provide("goog.html.SafeUrl");
|
|
9
|
+
goog.require("goog.asserts");
|
|
10
|
+
goog.require("goog.fs.url");
|
|
11
|
+
goog.require("goog.html.TrustedResourceUrl");
|
|
12
|
+
goog.require("goog.string.Const");
|
|
13
|
+
goog.require("goog.string.TypedString");
|
|
14
|
+
goog.require("goog.string.internal");
|
|
15
|
+
goog.html.SafeUrl = class {
|
|
16
|
+
constructor(value, token) {
|
|
17
|
+
this.privateDoNotAccessOrElseSafeUrlWrappedValue_ = token === goog.html.SafeUrl.CONSTRUCTOR_TOKEN_PRIVATE_ ? value : "";
|
|
18
|
+
}
|
|
19
|
+
toString() {
|
|
20
|
+
return this.privateDoNotAccessOrElseSafeUrlWrappedValue_.toString();
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
goog.html.SafeUrl.INNOCUOUS_STRING = "about:invalid#zClosurez";
|
|
24
|
+
goog.html.SafeUrl.prototype.implementsGoogStringTypedString = true;
|
|
25
|
+
goog.html.SafeUrl.prototype.getTypedStringValue = function() {
|
|
26
|
+
return this.privateDoNotAccessOrElseSafeUrlWrappedValue_.toString();
|
|
27
|
+
};
|
|
28
|
+
goog.html.SafeUrl.unwrap = function(safeUrl) {
|
|
29
|
+
if (safeUrl instanceof goog.html.SafeUrl && safeUrl.constructor === goog.html.SafeUrl) {
|
|
30
|
+
return safeUrl.privateDoNotAccessOrElseSafeUrlWrappedValue_;
|
|
31
|
+
} else {
|
|
32
|
+
goog.asserts.fail("expected object of type SafeUrl, got '" + safeUrl + "' of type " + goog.typeOf(safeUrl));
|
|
33
|
+
return "type_error:SafeUrl";
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
goog.html.SafeUrl.fromConstant = function(url) {
|
|
37
|
+
return goog.html.SafeUrl.createSafeUrlSecurityPrivateDoNotAccessOrElse(goog.string.Const.unwrap(url));
|
|
38
|
+
};
|
|
39
|
+
goog.html.SAFE_MIME_TYPE_PATTERN_ = new RegExp("^(?:audio/(?:3gpp2|3gpp|aac|L16|midi|mp3|mp4|mpeg|oga|ogg|opus|x-m4a|x-matroska|x-wav|wav|webm)|" + "font/\\w+|" + "image/(?:bmp|gif|jpeg|jpg|png|tiff|webp|x-icon|heic|heif)|" + "video/(?:mpeg|mp4|ogg|webm|quicktime|x-matroska))" + '(?:;\\w+\x3d(?:\\w+|"[\\w;,\x3d ]+"))*$', "i");
|
|
40
|
+
goog.html.SafeUrl.isSafeMimeType = function(mimeType) {
|
|
41
|
+
return goog.html.SAFE_MIME_TYPE_PATTERN_.test(mimeType);
|
|
42
|
+
};
|
|
43
|
+
goog.html.SafeUrl.fromBlob = function(blob) {
|
|
44
|
+
var url = goog.html.SafeUrl.isSafeMimeType(blob.type) ? goog.fs.url.createObjectUrl(blob) : goog.html.SafeUrl.INNOCUOUS_STRING;
|
|
45
|
+
return goog.html.SafeUrl.createSafeUrlSecurityPrivateDoNotAccessOrElse(url);
|
|
46
|
+
};
|
|
47
|
+
goog.html.SafeUrl.revokeObjectUrl = function(safeUrl) {
|
|
48
|
+
var url = safeUrl.getTypedStringValue();
|
|
49
|
+
if (url !== goog.html.SafeUrl.INNOCUOUS_STRING) {
|
|
50
|
+
goog.fs.url.revokeObjectUrl(url);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
goog.html.SafeUrl.fromMediaSource = function(mediaSource) {
|
|
54
|
+
goog.asserts.assert("MediaSource" in goog.global, "No support for MediaSource");
|
|
55
|
+
const url = mediaSource instanceof MediaSource ? goog.fs.url.createObjectUrl(mediaSource) : goog.html.SafeUrl.INNOCUOUS_STRING;
|
|
56
|
+
return goog.html.SafeUrl.createSafeUrlSecurityPrivateDoNotAccessOrElse(url);
|
|
57
|
+
};
|
|
58
|
+
goog.html.DATA_URL_PATTERN_ = /^data:(.*);base64,[a-z0-9+\/]+=*$/i;
|
|
59
|
+
goog.html.SafeUrl.tryFromDataUrl = function(dataUrl) {
|
|
60
|
+
dataUrl = String(dataUrl);
|
|
61
|
+
var filteredDataUrl = dataUrl.replace(/(%0A|%0D)/g, "");
|
|
62
|
+
var match = filteredDataUrl.match(goog.html.DATA_URL_PATTERN_);
|
|
63
|
+
if (match) {
|
|
64
|
+
return goog.html.SafeUrl.createSafeUrlSecurityPrivateDoNotAccessOrElse(filteredDataUrl);
|
|
65
|
+
}
|
|
66
|
+
return null;
|
|
67
|
+
};
|
|
68
|
+
goog.html.SafeUrl.fromDataUrl = function(dataUrl) {
|
|
69
|
+
return goog.html.SafeUrl.tryFromDataUrl(dataUrl) || goog.html.SafeUrl.INNOCUOUS_URL;
|
|
70
|
+
};
|
|
71
|
+
goog.html.SafeUrl.fromTelUrl = function(telUrl) {
|
|
72
|
+
if (!goog.string.internal.caseInsensitiveStartsWith(telUrl, "tel:")) {
|
|
73
|
+
telUrl = goog.html.SafeUrl.INNOCUOUS_STRING;
|
|
74
|
+
}
|
|
75
|
+
return goog.html.SafeUrl.createSafeUrlSecurityPrivateDoNotAccessOrElse(telUrl);
|
|
76
|
+
};
|
|
77
|
+
goog.html.SIP_URL_PATTERN_ = new RegExp("^sip[s]?:[+a-z0-9_.!$%\x26'*\\/\x3d^`{|}~-]+@([a-z0-9-]+\\.)+[a-z0-9]{2,63}$", "i");
|
|
78
|
+
goog.html.SafeUrl.fromSipUrl = function(sipUrl) {
|
|
79
|
+
if (!goog.html.SIP_URL_PATTERN_.test(decodeURIComponent(sipUrl))) {
|
|
80
|
+
sipUrl = goog.html.SafeUrl.INNOCUOUS_STRING;
|
|
81
|
+
}
|
|
82
|
+
return goog.html.SafeUrl.createSafeUrlSecurityPrivateDoNotAccessOrElse(sipUrl);
|
|
83
|
+
};
|
|
84
|
+
goog.html.SafeUrl.fromFacebookMessengerUrl = function(facebookMessengerUrl) {
|
|
85
|
+
if (!goog.string.internal.caseInsensitiveStartsWith(facebookMessengerUrl, "fb-messenger://share")) {
|
|
86
|
+
facebookMessengerUrl = goog.html.SafeUrl.INNOCUOUS_STRING;
|
|
87
|
+
}
|
|
88
|
+
return goog.html.SafeUrl.createSafeUrlSecurityPrivateDoNotAccessOrElse(facebookMessengerUrl);
|
|
89
|
+
};
|
|
90
|
+
goog.html.SafeUrl.fromWhatsAppUrl = function(whatsAppUrl) {
|
|
91
|
+
if (!goog.string.internal.caseInsensitiveStartsWith(whatsAppUrl, "whatsapp://send")) {
|
|
92
|
+
whatsAppUrl = goog.html.SafeUrl.INNOCUOUS_STRING;
|
|
93
|
+
}
|
|
94
|
+
return goog.html.SafeUrl.createSafeUrlSecurityPrivateDoNotAccessOrElse(whatsAppUrl);
|
|
95
|
+
};
|
|
96
|
+
goog.html.SafeUrl.fromSmsUrl = function(smsUrl) {
|
|
97
|
+
if (!goog.string.internal.caseInsensitiveStartsWith(smsUrl, "sms:") || !goog.html.SafeUrl.isSmsUrlBodyValid_(smsUrl)) {
|
|
98
|
+
smsUrl = goog.html.SafeUrl.INNOCUOUS_STRING;
|
|
99
|
+
}
|
|
100
|
+
return goog.html.SafeUrl.createSafeUrlSecurityPrivateDoNotAccessOrElse(smsUrl);
|
|
101
|
+
};
|
|
102
|
+
goog.html.SafeUrl.isSmsUrlBodyValid_ = function(smsUrl) {
|
|
103
|
+
var hash = smsUrl.indexOf("#");
|
|
104
|
+
if (hash > 0) {
|
|
105
|
+
smsUrl = smsUrl.substring(0, hash);
|
|
106
|
+
}
|
|
107
|
+
var bodyParams = smsUrl.match(/[?&]body=/gi);
|
|
108
|
+
if (!bodyParams) {
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
if (bodyParams.length > 1) {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
var bodyValue = smsUrl.match(/[?&]body=([^&]*)/)[1];
|
|
115
|
+
if (!bodyValue) {
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
118
|
+
try {
|
|
119
|
+
decodeURIComponent(bodyValue);
|
|
120
|
+
} catch (error) {
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
return /^(?:[a-z0-9\-_.~]|%[0-9a-f]{2})+$/i.test(bodyValue);
|
|
124
|
+
};
|
|
125
|
+
goog.html.SafeUrl.fromSshUrl = function(sshUrl) {
|
|
126
|
+
if (!goog.string.internal.caseInsensitiveStartsWith(sshUrl, "ssh://")) {
|
|
127
|
+
sshUrl = goog.html.SafeUrl.INNOCUOUS_STRING;
|
|
128
|
+
}
|
|
129
|
+
return goog.html.SafeUrl.createSafeUrlSecurityPrivateDoNotAccessOrElse(sshUrl);
|
|
130
|
+
};
|
|
131
|
+
goog.html.SafeUrl.sanitizeChromeExtensionUrl = function(url, extensionId) {
|
|
132
|
+
return goog.html.SafeUrl.sanitizeExtensionUrl_(/^chrome-extension:\/\/([^\/]+)\//, url, extensionId);
|
|
133
|
+
};
|
|
134
|
+
goog.html.SafeUrl.sanitizeFirefoxExtensionUrl = function(url, extensionId) {
|
|
135
|
+
return goog.html.SafeUrl.sanitizeExtensionUrl_(/^moz-extension:\/\/([^\/]+)\//, url, extensionId);
|
|
136
|
+
};
|
|
137
|
+
goog.html.SafeUrl.sanitizeEdgeExtensionUrl = function(url, extensionId) {
|
|
138
|
+
return goog.html.SafeUrl.sanitizeExtensionUrl_(/^ms-browser-extension:\/\/([^\/]+)\//, url, extensionId);
|
|
139
|
+
};
|
|
140
|
+
goog.html.SafeUrl.sanitizeExtensionUrl_ = function(scheme, url, extensionId) {
|
|
141
|
+
var matches = scheme.exec(url);
|
|
142
|
+
if (!matches) {
|
|
143
|
+
url = goog.html.SafeUrl.INNOCUOUS_STRING;
|
|
144
|
+
} else {
|
|
145
|
+
var extractedExtensionId = matches[1];
|
|
146
|
+
var acceptedExtensionIds;
|
|
147
|
+
if (extensionId instanceof goog.string.Const) {
|
|
148
|
+
acceptedExtensionIds = [goog.string.Const.unwrap(extensionId)];
|
|
149
|
+
} else {
|
|
150
|
+
acceptedExtensionIds = extensionId.map(function unwrap(x) {
|
|
151
|
+
return goog.string.Const.unwrap(x);
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
if (acceptedExtensionIds.indexOf(extractedExtensionId) == -1) {
|
|
155
|
+
url = goog.html.SafeUrl.INNOCUOUS_STRING;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return goog.html.SafeUrl.createSafeUrlSecurityPrivateDoNotAccessOrElse(url);
|
|
159
|
+
};
|
|
160
|
+
goog.html.SafeUrl.fromTrustedResourceUrl = function(trustedResourceUrl) {
|
|
161
|
+
return goog.html.SafeUrl.createSafeUrlSecurityPrivateDoNotAccessOrElse(goog.html.TrustedResourceUrl.unwrap(trustedResourceUrl));
|
|
162
|
+
};
|
|
163
|
+
goog.html.SAFE_URL_PATTERN_ = /^(?:(?:https?|mailto|ftp):|[^:/?#]*(?:[/?#]|$))/i;
|
|
164
|
+
goog.html.SafeUrl.SAFE_URL_PATTERN = goog.html.SAFE_URL_PATTERN_;
|
|
165
|
+
goog.html.SafeUrl.trySanitize = function(url) {
|
|
166
|
+
if (url instanceof goog.html.SafeUrl) {
|
|
167
|
+
return url;
|
|
168
|
+
}
|
|
169
|
+
if (typeof url == "object" && url.implementsGoogStringTypedString) {
|
|
170
|
+
url = url.getTypedStringValue();
|
|
171
|
+
} else {
|
|
172
|
+
url = String(url);
|
|
173
|
+
}
|
|
174
|
+
if (!goog.html.SAFE_URL_PATTERN_.test(url)) {
|
|
175
|
+
return goog.html.SafeUrl.tryFromDataUrl(url);
|
|
176
|
+
}
|
|
177
|
+
return goog.html.SafeUrl.createSafeUrlSecurityPrivateDoNotAccessOrElse(url);
|
|
178
|
+
};
|
|
179
|
+
goog.html.SafeUrl.sanitize = function(url) {
|
|
180
|
+
return goog.html.SafeUrl.trySanitize(url) || goog.html.SafeUrl.INNOCUOUS_URL;
|
|
181
|
+
};
|
|
182
|
+
goog.html.SafeUrl.sanitizeAssertUnchanged = function(url, opt_allowDataUrl) {
|
|
183
|
+
if (url instanceof goog.html.SafeUrl) {
|
|
184
|
+
return url;
|
|
185
|
+
} else if (typeof url == "object" && url.implementsGoogStringTypedString) {
|
|
186
|
+
url = url.getTypedStringValue();
|
|
187
|
+
} else {
|
|
188
|
+
url = String(url);
|
|
189
|
+
}
|
|
190
|
+
if (opt_allowDataUrl && /^data:/i.test(url)) {
|
|
191
|
+
var safeUrl = goog.html.SafeUrl.fromDataUrl(url);
|
|
192
|
+
if (safeUrl.getTypedStringValue() == url) {
|
|
193
|
+
return safeUrl;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
if (!goog.asserts.assert(goog.html.SAFE_URL_PATTERN_.test(url), "%s does not match the safe URL pattern", url)) {
|
|
197
|
+
url = goog.html.SafeUrl.INNOCUOUS_STRING;
|
|
198
|
+
}
|
|
199
|
+
return goog.html.SafeUrl.createSafeUrlSecurityPrivateDoNotAccessOrElse(url);
|
|
200
|
+
};
|
|
201
|
+
goog.html.SafeUrl.extractScheme = function(url) {
|
|
202
|
+
let parsedUrl;
|
|
203
|
+
try {
|
|
204
|
+
parsedUrl = new URL(url);
|
|
205
|
+
} catch (e) {
|
|
206
|
+
return "https:";
|
|
207
|
+
}
|
|
208
|
+
return parsedUrl.protocol;
|
|
209
|
+
};
|
|
210
|
+
goog.html.SafeUrl.sanitizeJavascriptUrlAssertUnchanged = function(url) {
|
|
211
|
+
if (url instanceof goog.html.SafeUrl) {
|
|
212
|
+
return url;
|
|
213
|
+
} else if (typeof url == "object" && url.implementsGoogStringTypedString) {
|
|
214
|
+
url = url.getTypedStringValue();
|
|
215
|
+
} else {
|
|
216
|
+
url = String(url);
|
|
217
|
+
}
|
|
218
|
+
const parsedScheme = goog.html.SafeUrl.extractScheme(url);
|
|
219
|
+
if (!goog.asserts.assert(parsedScheme !== "javascript:", "%s is a javascript: URL", url)) {
|
|
220
|
+
url = goog.html.SafeUrl.INNOCUOUS_STRING;
|
|
221
|
+
}
|
|
222
|
+
return goog.html.SafeUrl.createSafeUrlSecurityPrivateDoNotAccessOrElse(url);
|
|
223
|
+
};
|
|
224
|
+
goog.html.SafeUrl.CONSTRUCTOR_TOKEN_PRIVATE_ = {};
|
|
225
|
+
goog.html.SafeUrl.createSafeUrlSecurityPrivateDoNotAccessOrElse = function(url) {
|
|
226
|
+
return new goog.html.SafeUrl(url, goog.html.SafeUrl.CONSTRUCTOR_TOKEN_PRIVATE_);
|
|
227
|
+
};
|
|
228
|
+
goog.html.SafeUrl.INNOCUOUS_URL = goog.html.SafeUrl.createSafeUrlSecurityPrivateDoNotAccessOrElse(goog.html.SafeUrl.INNOCUOUS_STRING);
|
|
229
|
+
goog.html.SafeUrl.ABOUT_BLANK = goog.html.SafeUrl.createSafeUrlSecurityPrivateDoNotAccessOrElse("about:blank");
|
|
230
|
+
|
|
231
|
+
//# sourceMappingURL=goog.html.safeurl.js.map
|