@angular/platform-browser 5.2.1 → 5.2.5

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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Angular v5.2.1
2
+ * @license Angular v5.2.5
3
3
  * (c) 2010-2018 Google, Inc. https://angular.io/
4
4
  * License: MIT
5
5
  */
@@ -3718,6 +3718,207 @@ var KeyEventsPlugin = /** @class */ (function (_super) {
3718
3718
  return KeyEventsPlugin;
3719
3719
  }(EventManagerPlugin));
3720
3720
 
3721
+ /**
3722
+ * @fileoverview added by tsickle
3723
+ * @suppress {checkTypes} checked by tsc
3724
+ */
3725
+ /**
3726
+ * @license
3727
+ * Copyright Google Inc. All Rights Reserved.
3728
+ *
3729
+ * Use of this source code is governed by an MIT-style license that can be
3730
+ * found in the LICENSE file at https://angular.io/license
3731
+ */
3732
+ /**
3733
+ * This helper class is used to get hold of an inert tree of DOM elements containing dirty HTML
3734
+ * that needs sanitizing.
3735
+ * Depending upon browser support we must use one of three strategies for doing this.
3736
+ * Support: Safari 10.x -> XHR strategy
3737
+ * Support: Firefox -> DomParser strategy
3738
+ * Default: InertDocument strategy
3739
+ */
3740
+ var InertBodyHelper = /** @class */ (function () {
3741
+ function InertBodyHelper(defaultDoc, DOM) {
3742
+ this.defaultDoc = defaultDoc;
3743
+ this.DOM = DOM;
3744
+ var /** @type {?} */ inertDocument = this.DOM.createHtmlDocument();
3745
+ this.inertBodyElement = inertDocument.body;
3746
+ if (this.inertBodyElement == null) {
3747
+ // usually there should be only one body element in the document, but IE doesn't have any, so
3748
+ // we need to create one.
3749
+ var /** @type {?} */ inertHtml = this.DOM.createElement('html', inertDocument);
3750
+ this.inertBodyElement = this.DOM.createElement('body', inertDocument);
3751
+ this.DOM.appendChild(inertHtml, this.inertBodyElement);
3752
+ this.DOM.appendChild(inertDocument, inertHtml);
3753
+ }
3754
+ this.DOM.setInnerHTML(this.inertBodyElement, '<svg><g onload="this.parentNode.remove()"></g></svg>');
3755
+ if (this.inertBodyElement.querySelector && !this.inertBodyElement.querySelector('svg')) {
3756
+ // We just hit the Safari 10.1 bug - which allows JS to run inside the SVG G element
3757
+ // so use the XHR strategy.
3758
+ this.getInertBodyElement = this.getInertBodyElement_XHR;
3759
+ return;
3760
+ }
3761
+ this.DOM.setInnerHTML(this.inertBodyElement, '<svg><p><style><img src="</style><img src=x onerror=alert(1)//">');
3762
+ if (this.inertBodyElement.querySelector && this.inertBodyElement.querySelector('svg img')) {
3763
+ // We just hit the Firefox bug - which prevents the inner img JS from being sanitized
3764
+ // so use the DOMParser strategy, if it is available.
3765
+ // If the DOMParser is not available then we are not in Firefox (Server/WebWorker?) so we
3766
+ // fall through to the default strategy below.
3767
+ if (isDOMParserAvailable()) {
3768
+ this.getInertBodyElement = this.getInertBodyElement_DOMParser;
3769
+ return;
3770
+ }
3771
+ }
3772
+ // None of the bugs were hit so it is safe for us to use the default InertDocument strategy
3773
+ this.getInertBodyElement = this.getInertBodyElement_InertDocument;
3774
+ }
3775
+ /**
3776
+ * Use XHR to create and fill an inert body element (on Safari 10.1)
3777
+ * See
3778
+ * https://github.com/cure53/DOMPurify/blob/a992d3a75031cb8bb032e5ea8399ba972bdf9a65/src/purify.js#L439-L449
3779
+ * @param {?} html
3780
+ * @return {?}
3781
+ */
3782
+ InertBodyHelper.prototype.getInertBodyElement_XHR = /**
3783
+ * Use XHR to create and fill an inert body element (on Safari 10.1)
3784
+ * See
3785
+ * https://github.com/cure53/DOMPurify/blob/a992d3a75031cb8bb032e5ea8399ba972bdf9a65/src/purify.js#L439-L449
3786
+ * @param {?} html
3787
+ * @return {?}
3788
+ */
3789
+ function (html) {
3790
+ // We add these extra elements to ensure that the rest of the content is parsed as expected
3791
+ // e.g. leading whitespace is maintained and tags like `<meta>` do not get hoisted to the
3792
+ // `<head>` tag.
3793
+ html = '<body><remove></remove>' + html + '</body>';
3794
+ try {
3795
+ html = encodeURI(html);
3796
+ }
3797
+ catch (/** @type {?} */ e) {
3798
+ return null;
3799
+ }
3800
+ var /** @type {?} */ xhr = new XMLHttpRequest();
3801
+ xhr.responseType = 'document';
3802
+ xhr.open('GET', 'data:text/html;charset=utf-8,' + html, false);
3803
+ xhr.send(null);
3804
+ var /** @type {?} */ body = xhr.response.body;
3805
+ body.removeChild(/** @type {?} */ ((body.firstChild)));
3806
+ return body;
3807
+ };
3808
+ /**
3809
+ * Use DOMParser to create and fill an inert body element (on Firefox)
3810
+ * See https://github.com/cure53/DOMPurify/releases/tag/0.6.7
3811
+ *
3812
+ * @param {?} html
3813
+ * @return {?}
3814
+ */
3815
+ InertBodyHelper.prototype.getInertBodyElement_DOMParser = /**
3816
+ * Use DOMParser to create and fill an inert body element (on Firefox)
3817
+ * See https://github.com/cure53/DOMPurify/releases/tag/0.6.7
3818
+ *
3819
+ * @param {?} html
3820
+ * @return {?}
3821
+ */
3822
+ function (html) {
3823
+ // We add these extra elements to ensure that the rest of the content is parsed as expected
3824
+ // e.g. leading whitespace is maintained and tags like `<meta>` do not get hoisted to the
3825
+ // `<head>` tag.
3826
+ html = '<body><remove></remove>' + html + '</body>';
3827
+ try {
3828
+ var /** @type {?} */ body = /** @type {?} */ (new (/** @type {?} */ (window))
3829
+ .DOMParser()
3830
+ .parseFromString(html, 'text/html')
3831
+ .body);
3832
+ body.removeChild(/** @type {?} */ ((body.firstChild)));
3833
+ return body;
3834
+ }
3835
+ catch (/** @type {?} */ e) {
3836
+ return null;
3837
+ }
3838
+ };
3839
+ /**
3840
+ * Use an HTML5 `template` element, if supported, or an inert body element created via
3841
+ * `createHtmlDocument` to create and fill an inert DOM element.
3842
+ * This is the default sane strategy to use if the browser does not require one of the specialised
3843
+ * strategies above.
3844
+ * @param {?} html
3845
+ * @return {?}
3846
+ */
3847
+ InertBodyHelper.prototype.getInertBodyElement_InertDocument = /**
3848
+ * Use an HTML5 `template` element, if supported, or an inert body element created via
3849
+ * `createHtmlDocument` to create and fill an inert DOM element.
3850
+ * This is the default sane strategy to use if the browser does not require one of the specialised
3851
+ * strategies above.
3852
+ * @param {?} html
3853
+ * @return {?}
3854
+ */
3855
+ function (html) {
3856
+ // Prefer using <template> element if supported.
3857
+ var /** @type {?} */ templateEl = this.DOM.createElement('template');
3858
+ if ('content' in templateEl) {
3859
+ this.DOM.setInnerHTML(templateEl, html);
3860
+ return templateEl;
3861
+ }
3862
+ this.DOM.setInnerHTML(this.inertBodyElement, html);
3863
+ // Support: IE 9-11 only
3864
+ // strip custom-namespaced attributes on IE<=11
3865
+ if (this.defaultDoc.documentMode) {
3866
+ this.stripCustomNsAttrs(this.inertBodyElement);
3867
+ }
3868
+ return this.inertBodyElement;
3869
+ };
3870
+ /**
3871
+ * When IE9-11 comes across an unknown namespaced attribute e.g. 'xlink:foo' it adds 'xmlns:ns1'
3872
+ * attribute to declare ns1 namespace and prefixes the attribute with 'ns1' (e.g.
3873
+ * 'ns1:xlink:foo').
3874
+ *
3875
+ * This is undesirable since we don't want to allow any of these custom attributes. This method
3876
+ * strips them all.
3877
+ * @param {?} el
3878
+ * @return {?}
3879
+ */
3880
+ InertBodyHelper.prototype.stripCustomNsAttrs = /**
3881
+ * When IE9-11 comes across an unknown namespaced attribute e.g. 'xlink:foo' it adds 'xmlns:ns1'
3882
+ * attribute to declare ns1 namespace and prefixes the attribute with 'ns1' (e.g.
3883
+ * 'ns1:xlink:foo').
3884
+ *
3885
+ * This is undesirable since we don't want to allow any of these custom attributes. This method
3886
+ * strips them all.
3887
+ * @param {?} el
3888
+ * @return {?}
3889
+ */
3890
+ function (el) {
3891
+ var _this = this;
3892
+ this.DOM.attributeMap(el).forEach(function (_, attrName) {
3893
+ if (attrName === 'xmlns:ns1' || attrName.indexOf('ns1:') === 0) {
3894
+ _this.DOM.removeAttribute(el, attrName);
3895
+ }
3896
+ });
3897
+ for (var _i = 0, _a = this.DOM.childNodesAsList(el); _i < _a.length; _i++) {
3898
+ var n = _a[_i];
3899
+ if (this.DOM.isElementNode(n))
3900
+ this.stripCustomNsAttrs(/** @type {?} */ (n));
3901
+ }
3902
+ };
3903
+ return InertBodyHelper;
3904
+ }());
3905
+ /**
3906
+ * We need to determine whether the DOMParser exists in the global context.
3907
+ * The try-catch is because, on some browsers, trying to access this property
3908
+ * on window can actually throw an error.
3909
+ *
3910
+ * @suppress {uselessCode}
3911
+ * @return {?}
3912
+ */
3913
+ function isDOMParserAvailable() {
3914
+ try {
3915
+ return !!(/** @type {?} */ (window)).DOMParser;
3916
+ }
3917
+ catch (/** @type {?} */ e) {
3918
+ return false;
3919
+ }
3920
+ }
3921
+
3721
3922
  /**
3722
3923
  * @fileoverview added by tsickle
3723
3924
  * @suppress {checkTypes} checked by tsc
@@ -3793,38 +3994,6 @@ function sanitizeSrcset(srcset) {
3793
3994
  * Use of this source code is governed by an MIT-style license that can be
3794
3995
  * found in the LICENSE file at https://angular.io/license
3795
3996
  */
3796
- /**
3797
- * A <body> element that can be safely used to parse untrusted HTML. Lazily initialized below.
3798
- */
3799
- var inertElement = null;
3800
- /**
3801
- * Lazily initialized to make sure the DOM adapter gets set before use.
3802
- */
3803
- var DOM = /** @type {?} */ ((null));
3804
- /**
3805
- * Returns an HTML element that is guaranteed to not execute code when creating elements in it.
3806
- * @return {?}
3807
- */
3808
- function getInertElement() {
3809
- if (inertElement)
3810
- return inertElement;
3811
- DOM = getDOM();
3812
- // Prefer using <template> element if supported.
3813
- var /** @type {?} */ templateEl = DOM.createElement('template');
3814
- if ('content' in templateEl)
3815
- return templateEl;
3816
- var /** @type {?} */ doc = DOM.createHtmlDocument();
3817
- inertElement = DOM.querySelector(doc, 'body');
3818
- if (inertElement == null) {
3819
- // usually there should be only one body element in the document, but IE doesn't have any, so we
3820
- // need to create one.
3821
- var /** @type {?} */ html = DOM.createElement('html', doc);
3822
- inertElement = DOM.createElement('body', doc);
3823
- DOM.appendChild(html, inertElement);
3824
- DOM.appendChild(doc, html);
3825
- }
3826
- return inertElement;
3827
- }
3828
3997
  /**
3829
3998
  * @param {?} tags
3830
3999
  * @return {?}
@@ -3900,6 +4069,7 @@ var SanitizingHtmlSerializer = /** @class */ (function () {
3900
4069
  function SanitizingHtmlSerializer() {
3901
4070
  this.sanitizedSomething = false;
3902
4071
  this.buf = [];
4072
+ this.DOM = getDOM();
3903
4073
  }
3904
4074
  /**
3905
4075
  * @param {?} el
@@ -3913,33 +4083,33 @@ var SanitizingHtmlSerializer = /** @class */ (function () {
3913
4083
  // This cannot use a TreeWalker, as it has to run on Angular's various DOM adapters.
3914
4084
  // However this code never accesses properties off of `document` before deleting its contents
3915
4085
  // again, so it shouldn't be vulnerable to DOM clobbering.
3916
- var /** @type {?} */ current = /** @type {?} */ ((el.firstChild));
4086
+ var /** @type {?} */ current = /** @type {?} */ ((this.DOM.firstChild(el)));
3917
4087
  while (current) {
3918
- if (DOM.isElementNode(current)) {
4088
+ if (this.DOM.isElementNode(current)) {
3919
4089
  this.startElement(/** @type {?} */ (current));
3920
4090
  }
3921
- else if (DOM.isTextNode(current)) {
3922
- this.chars(/** @type {?} */ ((DOM.nodeValue(current))));
4091
+ else if (this.DOM.isTextNode(current)) {
4092
+ this.chars(/** @type {?} */ ((this.DOM.nodeValue(current))));
3923
4093
  }
3924
4094
  else {
3925
4095
  // Strip non-element, non-text nodes.
3926
4096
  this.sanitizedSomething = true;
3927
4097
  }
3928
- if (DOM.firstChild(current)) {
3929
- current = /** @type {?} */ ((DOM.firstChild(current)));
4098
+ if (this.DOM.firstChild(current)) {
4099
+ current = /** @type {?} */ ((this.DOM.firstChild(current)));
3930
4100
  continue;
3931
4101
  }
3932
4102
  while (current) {
3933
4103
  // Leaving the element. Walk up and to the right, closing tags as we go.
3934
- if (DOM.isElementNode(current)) {
4104
+ if (this.DOM.isElementNode(current)) {
3935
4105
  this.endElement(/** @type {?} */ (current));
3936
4106
  }
3937
- var /** @type {?} */ next = checkClobberedElement(current, /** @type {?} */ ((DOM.nextSibling(current))));
4107
+ var /** @type {?} */ next = this.checkClobberedElement(current, /** @type {?} */ ((this.DOM.nextSibling(current))));
3938
4108
  if (next) {
3939
4109
  current = next;
3940
4110
  break;
3941
4111
  }
3942
- current = checkClobberedElement(current, /** @type {?} */ ((DOM.parentElement(current))));
4112
+ current = this.checkClobberedElement(current, /** @type {?} */ ((this.DOM.parentElement(current))));
3943
4113
  }
3944
4114
  }
3945
4115
  return this.buf.join('');
@@ -3954,14 +4124,14 @@ var SanitizingHtmlSerializer = /** @class */ (function () {
3954
4124
  */
3955
4125
  function (element) {
3956
4126
  var _this = this;
3957
- var /** @type {?} */ tagName = DOM.nodeName(element).toLowerCase();
4127
+ var /** @type {?} */ tagName = this.DOM.nodeName(element).toLowerCase();
3958
4128
  if (!VALID_ELEMENTS.hasOwnProperty(tagName)) {
3959
4129
  this.sanitizedSomething = true;
3960
4130
  return;
3961
4131
  }
3962
4132
  this.buf.push('<');
3963
4133
  this.buf.push(tagName);
3964
- DOM.attributeMap(element).forEach(function (value, attrName) {
4134
+ this.DOM.attributeMap(element).forEach(function (value, attrName) {
3965
4135
  var /** @type {?} */ lower = attrName.toLowerCase();
3966
4136
  if (!VALID_ATTRS.hasOwnProperty(lower)) {
3967
4137
  _this.sanitizedSomething = true;
@@ -3989,7 +4159,7 @@ var SanitizingHtmlSerializer = /** @class */ (function () {
3989
4159
  * @return {?}
3990
4160
  */
3991
4161
  function (current) {
3992
- var /** @type {?} */ tagName = DOM.nodeName(current).toLowerCase();
4162
+ var /** @type {?} */ tagName = this.DOM.nodeName(current).toLowerCase();
3993
4163
  if (VALID_ELEMENTS.hasOwnProperty(tagName) && !VOID_ELEMENTS.hasOwnProperty(tagName)) {
3994
4164
  this.buf.push('</');
3995
4165
  this.buf.push(tagName);
@@ -4005,19 +4175,24 @@ var SanitizingHtmlSerializer = /** @class */ (function () {
4005
4175
  * @return {?}
4006
4176
  */
4007
4177
  function (chars) { this.buf.push(encodeEntities(chars)); };
4178
+ /**
4179
+ * @param {?} node
4180
+ * @param {?} nextNode
4181
+ * @return {?}
4182
+ */
4183
+ SanitizingHtmlSerializer.prototype.checkClobberedElement = /**
4184
+ * @param {?} node
4185
+ * @param {?} nextNode
4186
+ * @return {?}
4187
+ */
4188
+ function (node, nextNode) {
4189
+ if (nextNode && this.DOM.contains(node, nextNode)) {
4190
+ throw new Error("Failed to sanitize html because the element is clobbered: " + this.DOM.getOuterHTML(node));
4191
+ }
4192
+ return nextNode;
4193
+ };
4008
4194
  return SanitizingHtmlSerializer;
4009
4195
  }());
4010
- /**
4011
- * @param {?} node
4012
- * @param {?} nextNode
4013
- * @return {?}
4014
- */
4015
- function checkClobberedElement(node, nextNode) {
4016
- if (nextNode && DOM.contains(node, nextNode)) {
4017
- throw new Error("Failed to sanitize html because the element is clobbered: " + DOM.getOuterHTML(node));
4018
- }
4019
- return nextNode;
4020
- }
4021
4196
  // Regular Expressions for parsing tags and attributes
4022
4197
  var SURROGATE_PAIR_REGEXP = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
4023
4198
  // ! to ~ is the ASCII range.
@@ -4040,27 +4215,7 @@ function encodeEntities(value) {
4040
4215
  .replace(/</g, '&lt;')
4041
4216
  .replace(/>/g, '&gt;');
4042
4217
  }
4043
- /**
4044
- * When IE9-11 comes across an unknown namespaced attribute e.g. 'xlink:foo' it adds 'xmlns:ns1'
4045
- * attribute to declare ns1 namespace and prefixes the attribute with 'ns1' (e.g. 'ns1:xlink:foo').
4046
- *
4047
- * This is undesirable since we don't want to allow any of these custom attributes. This method
4048
- * strips them all.
4049
- * @param {?} el
4050
- * @return {?}
4051
- */
4052
- function stripCustomNsAttrs(el) {
4053
- DOM.attributeMap(el).forEach(function (_, attrName) {
4054
- if (attrName === 'xmlns:ns1' || attrName.indexOf('ns1:') === 0) {
4055
- DOM.removeAttribute(el, attrName);
4056
- }
4057
- });
4058
- for (var _i = 0, _a = DOM.childNodesAsList(el); _i < _a.length; _i++) {
4059
- var n = _a[_i];
4060
- if (DOM.isElementNode(n))
4061
- stripCustomNsAttrs(/** @type {?} */ (n));
4062
- }
4063
- }
4218
+ var inertBodyHelper;
4064
4219
  /**
4065
4220
  * Sanitizes the given unsafe, untrusted HTML fragment, and returns HTML text that is safe to add to
4066
4221
  * the DOM in a browser environment.
@@ -4069,10 +4224,13 @@ function stripCustomNsAttrs(el) {
4069
4224
  * @return {?}
4070
4225
  */
4071
4226
  function sanitizeHtml(defaultDoc, unsafeHtmlInput) {
4227
+ var /** @type {?} */ DOM = getDOM();
4228
+ var /** @type {?} */ inertBodyElement = null;
4072
4229
  try {
4073
- var /** @type {?} */ containerEl = getInertElement();
4230
+ inertBodyHelper = inertBodyHelper || new InertBodyHelper(defaultDoc, DOM);
4074
4231
  // Make sure unsafeHtml is actually a string (TypeScript types are not enforced at runtime).
4075
4232
  var /** @type {?} */ unsafeHtml = unsafeHtmlInput ? String(unsafeHtmlInput) : '';
4233
+ inertBodyElement = inertBodyHelper.getInertBodyElement(unsafeHtml);
4076
4234
  // mXSS protection. Repeatedly parse the document to make sure it stabilizes, so that a browser
4077
4235
  // trying to auto-correct incorrect HTML cannot cause formerly inert HTML to become dangerous.
4078
4236
  var /** @type {?} */ mXSSAttempts = 5;
@@ -4083,30 +4241,25 @@ function sanitizeHtml(defaultDoc, unsafeHtmlInput) {
4083
4241
  }
4084
4242
  mXSSAttempts--;
4085
4243
  unsafeHtml = parsedHtml;
4086
- DOM.setInnerHTML(containerEl, unsafeHtml);
4087
- if (defaultDoc.documentMode) {
4088
- // strip custom-namespaced attributes on IE<=11
4089
- stripCustomNsAttrs(containerEl);
4090
- }
4091
- parsedHtml = DOM.getInnerHTML(containerEl);
4244
+ parsedHtml = DOM.getInnerHTML(inertBodyElement);
4245
+ inertBodyElement = inertBodyHelper.getInertBodyElement(unsafeHtml);
4092
4246
  } while (unsafeHtml !== parsedHtml);
4093
4247
  var /** @type {?} */ sanitizer = new SanitizingHtmlSerializer();
4094
- var /** @type {?} */ safeHtml = sanitizer.sanitizeChildren(DOM.getTemplateContent(containerEl) || containerEl);
4095
- // Clear out the body element.
4096
- var /** @type {?} */ parent_1 = DOM.getTemplateContent(containerEl) || containerEl;
4097
- for (var _i = 0, _a = DOM.childNodesAsList(parent_1); _i < _a.length; _i++) {
4098
- var child = _a[_i];
4099
- DOM.removeChild(parent_1, child);
4100
- }
4248
+ var /** @type {?} */ safeHtml = sanitizer.sanitizeChildren(DOM.getTemplateContent(inertBodyElement) || inertBodyElement);
4101
4249
  if (isDevMode() && sanitizer.sanitizedSomething) {
4102
4250
  DOM.log('WARNING: sanitizing HTML stripped some content (see http://g.co/ng/security#xss).');
4103
4251
  }
4104
4252
  return safeHtml;
4105
4253
  }
4106
- catch (/** @type {?} */ e) {
4254
+ finally {
4107
4255
  // In case anything goes wrong, clear out inertElement to reset the entire DOM structure.
4108
- inertElement = null;
4109
- throw e;
4256
+ if (inertBodyElement) {
4257
+ var /** @type {?} */ parent_1 = DOM.getTemplateContent(inertBodyElement) || inertBodyElement;
4258
+ for (var _i = 0, _a = DOM.childNodesAsList(parent_1); _i < _a.length; _i++) {
4259
+ var child = _a[_i];
4260
+ DOM.removeChild(parent_1, child);
4261
+ }
4262
+ }
4110
4263
  }
4111
4264
  }
4112
4265
 
@@ -4917,7 +5070,9 @@ var TransferState = /** @class */ (function () {
4917
5070
  * @param {?} defaultValue
4918
5071
  * @return {?}
4919
5072
  */
4920
- function (key, defaultValue) { return /** @type {?} */ (this.store[key]) || defaultValue; };
5073
+ function (key, defaultValue) {
5074
+ return this.store[key] !== undefined ? /** @type {?} */ (this.store[key]) : defaultValue;
5075
+ };
4921
5076
  /**
4922
5077
  * Set the value corresponding to a key.
4923
5078
  */
@@ -5191,7 +5346,7 @@ var By = /** @class */ (function () {
5191
5346
  /**
5192
5347
  * \@stable
5193
5348
  */
5194
- var VERSION = new Version('5.2.1');
5349
+ var VERSION = new Version('5.2.5');
5195
5350
 
5196
5351
  /**
5197
5352
  * @fileoverview added by tsickle