@@ -15,8 +15,8 @@ var $sanitizeMinErr = angular.$$minErr('$sanitize');
15
15
var bind ;
16
16
var extend ;
17
17
var forEach ;
18
- var isDefined ;
19
18
var isArray ;
19
+ var isDefined ;
20
20
var isObject ;
21
21
var lowercase ;
22
22
var noop ;
@@ -146,8 +146,8 @@ var htmlSanitizeWriter;
146
146
* Creates and configures {@link $sanitize} instance.
147
147
*/
148
148
function $SanitizeProvider ( ) {
149
- var svgEnabled = false ;
150
149
var hasBeenInstantiated = false ;
150
+ var svgEnabled = false ;
151
151
152
152
this . $get = [ '$$sanitizeUri' , function ( $$sanitizeUri ) {
153
153
hasBeenInstantiated = true ;
@@ -191,7 +191,7 @@ function $SanitizeProvider() {
191
191
* </div>
192
192
*
193
193
* @param {boolean= } flag Enable or disable SVG support in the sanitizer.
194
- * @returns {boolean|ng. $sanitizeProvider } Returns the currently configured value if called
194
+ * @returns {boolean|$sanitizeProvider } Returns the currently configured value if called
195
195
* without an argument or self for chaining otherwise.
196
196
*/
197
197
this . enableSvg = function ( enableSvg ) {
@@ -209,27 +209,51 @@ function $SanitizeProvider() {
209
209
* @name $sanitizeProvider#addValidElements
210
210
* @kind function
211
211
*
212
- * @param {Array|Object } elements List of valid elements.
212
+ * @description
213
+ * Extends the built-in lists of valid HTML/SVG elements, i.e. elements that are considered safe
214
+ * and are not stripped off during sanitization. You can extend the following lists:
215
+ *
216
+ * - `htmlElements`: A list of elements (tag names) to extend the current list of safe HTML
217
+ * elements. HTML elements considered safe will not be removed during sanitization. All other
218
+ * elements will be stripped off.
219
+ *
220
+ * - `htmlVoidElements`: This is similar to `htmlElements`, but in addition allows the specified
221
+ * elements to have no end tag (similar to HTML
222
+ * [void elements](https://rawgit.com/w3c/html/html5.1-2/single-page.html#void-elements)).
223
+ *
224
+ * - `svgElements`: This is similar to `htmlElements`, but for SVG elements. This list is only
225
+ * taken into account if SVG is {@link ngSanitize.$sanitizeProvider#enableSvg enabled} for
226
+ * `$sanitize`.
227
+ *
228
+ * <div class="alert alert-warning">
229
+ * This method must be called during the {@link angular.Module#config config} phase. Once the
230
+ * `$sanitize` service has been instantiated, this method has no effect.
231
+ * </div>
232
+ *
233
+ * @param {Array<String>|Object } elements - A list of valid HTML elements or an object with one or
234
+ * more of the following properties:
235
+ * - **htmlElements** - `{Array<String>}` - A list of elements to extend the current list of
236
+ * HTML elements.
237
+ * - **htmlVoidElements** - `{Array<String>}` - A list of elements to extend the current list of
238
+ * void HTML elements; i.e. elements that do not have an end tag.
239
+ * - **svgElements** - `{Array<String>}` - A list of elements to extend the current list of SVG
240
+ * elements. The list of SVG elements is only taken into account if SVG is
241
+ * {@link ngSanitize.$sanitizeProvider#enableSvg enabled} for `$sanitize`.
213
242
*
214
- * Object properties:
243
+ * Passing an array (`[...]`) is equivalent to passing `{htmlElements: [...]}`.
215
244
*
216
- * - `svgElements` – `{string[]=}` – An array of SVG elements' names.
217
- * - `htmlVoidElements` – `{string[]=}` – An array of void elements' names.
218
- * - `htmlElements` – `{string[]=}` – An array of html elements' names.
245
+ * @return {$sanitizeProvider } Returns self for chaining.
219
246
*/
220
247
this . addValidElements = function ( elements ) {
221
- if ( hasBeenInstantiated ) return this ;
222
-
223
- if ( isArray ( elements ) ) {
224
- addElementsTo ( validElements , elements ) ;
225
- return this ;
226
- }
248
+ if ( ! hasBeenInstantiated ) {
249
+ if ( isArray ( elements ) ) {
250
+ elements = { htmlElements : elements } ;
251
+ }
227
252
228
- if ( isObject ( elements ) ) {
229
- addElementsTo ( svgElements , elements [ 'svgElements' ] ) ;
230
- addElementsTo ( voidElements , elements [ 'htmlVoidElements' ] ) ;
231
- addElementsTo ( validElements , elements [ 'htmlVoidElements' ] ) ;
232
- addElementsTo ( validElements , elements [ 'htmlElements' ] ) ;
253
+ addElementsTo ( svgElements , elements . svgElements ) ;
254
+ addElementsTo ( voidElements , elements . htmlVoidElements ) ;
255
+ addElementsTo ( validElements , elements . htmlVoidElements ) ;
256
+ addElementsTo ( validElements , elements . htmlElements ) ;
233
257
}
234
258
235
259
return this ;
@@ -242,14 +266,28 @@ function $SanitizeProvider() {
242
266
* @kind function
243
267
*
244
268
* @description
245
- * The added attributes will not be treated as URI attributes, which means their values will
246
- * not sanitized as URIs using the aHrefSanitizationWhitelist and imgSrcSanitizationWhitelist of {@link ng.$compileProvider $compileProvider}.
269
+ * Extends the built-in list of valid attributes, i.e. attributes that are considered safe and are
270
+ * not stripped off during sanitization.
271
+ *
272
+ * **Note**:
273
+ * The new attributes will not be treated as URI attributes, which means their values will not be
274
+ * sanitized as URIs using `$compileProvider`'s
275
+ * {@link ng.$compileProvider#aHrefSanitizationWhitelist aHrefSanitizationWhitelist} and
276
+ * {@link ng.$compileProvider#imgSrcSanitizationWhitelist imgSrcSanitizationWhitelist}.
247
277
*
248
- * @param {Array } attrs List of valid attributes
278
+ * <div class="alert alert-warning">
279
+ * This method must be called during the {@link angular.Module#config config} phase. Once the
280
+ * `$sanitize` service has been instantiated, this method has no effect.
281
+ * </div>
282
+ *
283
+ * @param {Array<String> } attrs - A list of valid attributes.
284
+ *
285
+ * @returns {$sanitizeProvider } Returns self for chaining.
249
286
*/
250
287
this . addValidAttrs = function ( attrs ) {
251
- if ( hasBeenInstantiated ) return this ;
252
- extend ( validAttrs , arrayToMap ( attrs , true ) ) ;
288
+ if ( ! hasBeenInstantiated ) {
289
+ extend ( validAttrs , arrayToMap ( attrs , true ) ) ;
290
+ }
253
291
return this ;
254
292
} ;
255
293
0 commit comments