Skip to content

Commit 4434689

Browse files
committed
Update HTML Sanitizer doc for max_input_length option
1 parent 9ce082c commit 4434689

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

html_sanitizer.rst

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,75 @@ the HTML sanitizer: ``src``, ``href``, ``lowsrc``, ``background`` and ``ping``.
943943
->allowRelativeMedias()
944944
);
945945
946+
Configure max input length
947+
~~~~~~~~~~~~~~~~~~~~~
948+
949+
Using this option, you can change the default max input length of ``20000`` characters.
950+
Any input longer than this value will be truncated.
951+
952+
.. configuration-block::
953+
954+
.. code-block:: yaml
955+
956+
# config/packages/html_sanitizer.yaml
957+
framework:
958+
html_sanitizer:
959+
sanitizers:
960+
app.post_sanitizer:
961+
# ...
962+
963+
# specifies the max input length. Inputs longer than this value will be
964+
# truncated (default: 20000)
965+
max_input_length: 20000
966+
967+
.. code-block:: xml
968+
969+
<!-- config/packages/html_sanitizer.xml -->
970+
<?xml version="1.0" encoding="UTF-8" ?>
971+
<container xmlns="http://symfony.com/schema/dic/services"
972+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
973+
xmlns:framework="http://symfony.com/schema/dic/symfony"
974+
xsi:schemaLocation="http://symfony.com/schema/dic/services
975+
https://symfony.com/schema/dic/services/services-1.0.xsd
976+
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
977+
978+
<framework:config>
979+
<framework:html-sanitizer>
980+
<framework:sanitizer name="app.post_sanitizer">
981+
<!-- specifies the max input length. Inputs longer than this value will be
982+
truncated (default: 20000) -->
983+
<framework:max-input-length>20000</framework:max-input-length>
984+
</framework:sanitizer>
985+
</framework:html-sanitizer>
986+
</framework:config>
987+
</container>
988+
989+
.. code-block:: php
990+
991+
// config/packages/framework.php
992+
use Symfony\Config\FrameworkConfig;
993+
994+
return static function (FrameworkConfig $framework) {
995+
$framework->htmlSanitizer()
996+
->sanitizer('app.post_sanitizer')
997+
// specifies the max input length. Inputs longer than this value will be
998+
// truncated (default: 20000)
999+
->withMaxInputLength(20000)
1000+
;
1001+
};
1002+
1003+
.. code-block:: php-standalone
1004+
1005+
use Symfony\Component\HtmlSanitizer\HtmlSanitizer;
1006+
use Symfony\Component\HtmlSanitizer\HtmlSanitizerConfig;
1007+
1008+
$postSanitizer = new HtmlSanitizer(
1009+
(new HtmlSanitizerConfig())
1010+
// specifies the max input length. Inputs longer than this value will be
1011+
// truncated (default: 20000)
1012+
->withMaxInputLength(20000)
1013+
);
1014+
9461015
Custom Attribute Sanitizers
9471016
~~~~~~~~~~~~~~~~~~~~~~~~~~~
9481017

0 commit comments

Comments
 (0)