Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 96bd3b1

Browse filesBrowse files
committed
[HtmlSanitizer] Add functions to handle operations on multiple attributes or elements at the same time
1 parent dc330b0 commit 96bd3b1
Copy full SHA for 96bd3b1

File tree

3 files changed

+290
-1
lines changed
Filter options

3 files changed

+290
-1
lines changed

‎src/Symfony/Component/HtmlSanitizer/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/HtmlSanitizer/CHANGELOG.md
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
7.1
5+
---
6+
7+
* Add functions to allow operations on arrays of attributes and elements at a time
8+
49
6.4
510
---
611

‎src/Symfony/Component/HtmlSanitizer/HtmlSanitizerConfig.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HtmlSanitizer/HtmlSanitizerConfig.php
+113Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,29 @@ public function allowElement(string $element, array|string $allowedAttributes =
274274
return $clone;
275275
}
276276

277+
/**
278+
* Configures the given elements as allowed.
279+
*
280+
* Allowed elements are elements the sanitizer should retain from the input.
281+
*
282+
* A list of allowed attributes for this element can be passed as a second argument.
283+
* Passing "*" will allow all standard attributes on this element. By default, no
284+
* attributes are allowed on the element.
285+
*
286+
* @param list<string> $elements
287+
* @param list<string>|string $allowedAttributes
288+
*/
289+
public function allowElements(array $elements, array|string $allowedAttributes = []): static
290+
{
291+
$clone = clone $this;
292+
293+
foreach ($elements as $element) {
294+
$clone = $clone->allowElement($element, $allowedAttributes);
295+
}
296+
297+
return $clone;
298+
}
299+
277300
/**
278301
* Configures the given element as blocked.
279302
*
@@ -292,6 +315,23 @@ public function blockElement(string $element): static
292315
return $clone;
293316
}
294317

318+
/**
319+
* Configures the given elements as blocked.
320+
*
321+
* Blocked elements are elements the sanitizer should remove from the input, but retain
322+
* their children.
323+
*/
324+
public function blockElements(array $elements): static
325+
{
326+
$clone = clone $this;
327+
328+
foreach ($elements as $element) {
329+
$clone = $clone->blockElement($element);
330+
}
331+
332+
return $clone;
333+
}
334+
295335
/**
296336
* Configures the given element as dropped.
297337
*
@@ -310,6 +350,29 @@ public function dropElement(string $element): static
310350
return $clone;
311351
}
312352

353+
/**
354+
* Configures the given elements as dropped.
355+
*
356+
* Dropped elements are elements the sanitizer should remove from the input, including
357+
* their children.
358+
*
359+
* Note: when using an empty configuration, all unknown elements are dropped
360+
* automatically. This method let you drop elements that were allowed earlier
361+
* in the configuration.
362+
*
363+
* @param list<string> $elements
364+
*/
365+
public function dropElements(array $elements): static
366+
{
367+
$clone = clone $this;
368+
369+
foreach ($elements as $element) {
370+
$clone = $clone->dropElement($element);
371+
}
372+
373+
return $clone;
374+
}
375+
313376
/**
314377
* Configures the given attribute as allowed.
315378
*
@@ -339,6 +402,30 @@ public function allowAttribute(string $attribute, array|string $allowedElements)
339402
return $clone;
340403
}
341404

405+
/**
406+
* Configures the given attributes as allowed.
407+
*
408+
* Allowed attributes are attributes the sanitizer should retain from the input.
409+
*
410+
* A list of allowed elements for these attributes can be passed as a second argument.
411+
* Passing "*" will allow all currently allowed elements to use this attribute.
412+
*
413+
* To configure each attribute for a specific element, please use the allowAttribute method instead.
414+
*
415+
* @param list<string> $attributes
416+
* @param list<string>|string $allowedElements
417+
*/
418+
public function allowAttributes(array $attributes, array|string $allowedElements): static
419+
{
420+
$clone = clone $this;
421+
422+
foreach ($attributes as $attribute) {
423+
$clone = $clone->allowAttribute($attribute, $allowedElements);
424+
}
425+
426+
return $clone;
427+
}
428+
342429
/**
343430
* Configures the given attribute as dropped.
344431
*
@@ -367,6 +454,32 @@ public function dropAttribute(string $attribute, array|string $droppedElements):
367454
return $clone;
368455
}
369456

457+
/**
458+
* Configures the given attributes as dropped.
459+
*
460+
* Dropped attributes are attributes the sanitizer should remove from the input.
461+
*
462+
* A list of elements on which to drop these attributes can be passed as a second argument.
463+
* Passing "*" will drop this attribute from all currently allowed elements.
464+
*
465+
* Note: when using an empty configuration, all unknown attributes are dropped
466+
* automatically. This method let you drop attributes that were allowed earlier
467+
* in the configuration.
468+
*
469+
* @param list<string> $attributes
470+
* @param list<string>|string $droppedElements
471+
*/
472+
public function dropAttributes(array $attributes, array|string $droppedElements): static
473+
{
474+
$clone = clone $this;
475+
476+
foreach ($attributes as $attribute) {
477+
$clone = $clone->dropAttribute($attribute, $droppedElements);
478+
}
479+
480+
return $clone;
481+
}
482+
370483
/**
371484
* Forcefully set the value of a given attribute on a given element.
372485
*

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.