gpt4 book ai didi

Cannot allow element (img: 'src') with symfony html-sanitizer (symfony6.3 php 8.2)(不能允许元素(img:‘src’)带有symfony html-saniizer(symfony6.3 php 8.2))

转载 作者:bug小助手 更新时间:2023-10-25 10:07:58 25 4
gpt4 key购买 nike



As per https://symfony.com/doc/current/html_sanitizer.html#allow-elements I created an html sanitizer implementation:

根据https://symfony.com/doc/current/html_sanitizer.html#allow-elements,我创建了一个html杀毒程序实现:



  • config/packages/html_sanitizer.yaml


framework:
html_sanitizer:
sanitizers:
app.post_sanitizer:
allow_safe_elements: true
#allow_static_elements: true
allow_elements:
img: '*'
#img: ['src', 'class']
span: '*'
p: 'class'


  • Controller/TestController.php


#[Route('/read_html', name: 'read_html')]
public function readHtml(HtmlSanitizerInterface $appPostSanitizer): Response {
$testHtml = '<div>
<span style="font-size: 21pt;">This some big text</span>
<img src="img_girl.jpg" alt="Girl in a jacket" width="500" height="600" class="img-fluid" >
<p class="text-danger">this is some red text in bootstrap!</p>
</div>';
$testHtml2 = $appPostSanitizer->sanitize($testHtml);
dd($testHtml, $testHtml2);
}


  • output:


"""
<div>
<span style="font-size: 21pt;">This some big text</span>
<img alt="Girl in a jacket" width="500" height="600" class="img-fluid" />
<p class="text-danger">this is some red text in bootstrap!</p>
</div>
"""

i.e. everything else works except src in img tag.

也就是说,除了img标记中的src之外,其他所有东西都可以工作。


src="img_girl.jpg" is missing.

SRC=“img_Girl.jpg”丢失。


I have tried any combination I could think of like :img: ['src', 'class'] img: 'src'.
Still could not make src show up after sanitization.

我尝试了我能想到的任何组合:img:[‘SRC’,‘CLASS’]img:‘SRC’。仍无法使src在消毒后出现。


更多回答

maybe you also need allow_relative_medias: true ?

也许您还需要允许_相对_媒体:真?

@Dirk J. Fabe : just checked it and it worked ! Thank you. Maybe add it as an answer so that i can accept it?

@Dirk J.Fabe:只要检查一下,它就起作用了!谢谢。也许添加它作为答案,这样我就可以接受它了?

优秀答案推荐

You must set allow_relative_medias: true.

您必须设置Allow_Relative_Medias:TRUE。


When you set allow_relative_medias to true, you instruct the sanitizer to make an exception for relative URLs. Relative URLs are URLs that do not include the full web address and protocol (e.g., img_girl.jpg).

当您将Allow_Relative_Medias设置为True时,您将指示杀毒程序对相对URL进行例外处理。相对URL是不包含完整网址和协议的URL(例如,img_Girl.jpg)。


Read more in the docs: https://symfony.com/doc/current/html_sanitizer.html#force-allow-media-urls

在文档中阅读更多内容:https://symfony.com/doc/current/html_sanitizer.html#force-allow-media-urls


更多回答

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com