使WordPress成为核心

变更集58040


忽略:
时间戳:
2024年4月24日上午07:43:02(5周(之前)
作者:
dmsnell公司
消息:

HTMLAPI:修复了对单长时髦评论的检测。

[60428]标签处理器一直在错误识别单个字符
古怪的评论。它一直声称
开头之后的时髦评论必须至少有三个字符(例如。
</1>),但它已经开始寻找结束>之后
这三个字符是一样的。这意味着它一直在跳过
这些古怪的注释的实际结束并吞没了下一个语法
直到找到一个>,通常使用进程中的下一个标记。

此修补程序修复了检测器并恢复查找以下标记。

开发于https://github.com/WordPress/WordPress-develop/pull/6412
在中讨论https://core.trac.wordpress.org/tickt/60170

后续行动[60428]
修复#60170
道具dmsnell、gziolo、jonsurerl。

位置:
大旅行箱
文件:
3编辑

图例:

未修改
补充
远离的
  • trunk/src/wp-includes/html-api/class-wp-html-tag-processor.php

    57987兰特 58040兰特  
    16301630             * https://html.spec.whatwg.org/multipage/parsing.html#标记-声明打开状态
    16311631             */
    1632 如果('!' === $html[$在+1处]){
     1632如果(! $此->是关闭标记&&'!' === $html[$在+1处]){
    16331633                /*
    16341634                 * `<!--` 转换到注释状态&应用进一步的注释规则。
     
    18101810             */
    18111811if('>'===$html[$at+1]){
     1812//`<>`被解释为纯文本。
     1813if(!$this->is_closingtag){
     1814++$在;
     1815继续;
     1816                }
     1817
    18121818$this->parser_state=self::state_PRESUMPTUOUS_TAG;
    18131819$this->token_length=$at+2-$this->token_starts_at;
     
    18201826*请参阅https://html.spec.whatwg.org/multipage/parsing.html#tag-开放状态
    18211827*/
    1822 如果('?' === $html[$在+1处]){
     1828如果(! $此->是关闭标记&&'?' === $html[$在+1处]){
    18231829$closer_at=strpos($html,'>',$at+2);
    18241830if(false===$closer_at){
     
    18921898                }
    18931899
    1894 $closer_at=strpos($html,'>',$at+);
     1900$closer_at=strpos($html,'>',$at+2);
    18951901if(false===$closer_at){
    18961902$this->parser_state=self::state_INCOMPLETE_INPUT;
  • trunk/tests/phpunit/tests/html-api/wpHtmlTagProcessor-token-scanning.php

    57508兰特 58040兰特  
    762762
    763763    /**
     764*确保正确解析各种时髦的评论。
     765     *
     766*@票60170
     767     *
     768*@自6.6.0起
     769     *
     770*@covers WP_HTML_Tag_Processor::next_token
     771     *
     772*@dataProvider data_various_funky_comments
     773     *
     774*@param string$funky_comment_html html包含一个时髦的注释。
     775*@param string$modifable_text HTML中第一条funky注释的可修改文本。
     776     */
     777公共函数test_various_funky_comments($funky注释html,$modifable_text){
     778$processor=新的WP_HTML_Tag_processor($funky_comment_HTML);
     779while('#funky-comment'!==$processor->get_token_type()&&$process->next_token()){
     780继续;
     781        }
     782
     783$this->资产相同(
     784“#funky-comment”,
     785$processor->get_token_type(),
     786“找不到预期的时髦评论。”
     787        );
     788
     789$this->资产相同(
     790$modifable_text,
     791$processor->get_modifable_text(),
     792“在一个古怪的评论中发现了错误的可修改文本跨度。”
     793        );
     794    }
     795
     796    /**
     797*数据提供商。
     798     *
     799*@return数组[]。
     800     */
     801公共静态函数data_various_funky_comments(){
     802返回数组(
     803“空格”=>数组(“</>”,“”),
     804'短带'=>数组('</!>','!'),
     805“问号”=>数组(“</?>”,“?”),
     806“短斜杠”=>数组(“<//>”,“/”),
     807“位(无属性)”=>数组(“<//wp:post-meta>”,“/wp:post-meta”),
     808“位(属性)”=>数组(“<//wp:post-meta-key=isbn>”,“/wp:post-meta-key=isbn”),
     809“卷曲”=>数组(“</{json}>”,“{json{”),
     810'在P'=>数组之前('</1><P>','1'),
     811'在P'=>数组之后('<P></__(“阅读更多”)></P>','__(“读取更多”)'),
     812“引用”=>数组(“</&gt;>”,“&gt;”),
     813        );
     814    }
     815
     816    /**
    764817*用双引号包装字符串的测试助手。
    765818     *
  • trunk/tests/phpunit/tests/interactivity-api/wpInteractivityAPI.php

    57987兰特 58040兰特  
    589589     *
    590590*@covers::process_directives
    591      */
    592 公共函数test_process_directives_doesnt_change_html_if_contains_unbalanced_tags(){
     591     *
     592*@dataProvider data_html_with_unbalanced_tags
     593     *
     594*@param string$html html包含不平衡标记和指令。
     595     */
     596公共函数test_process_directives_doesnt_change_html_if_contains_unbalanced_tags($html){
    593597$this->interactivity->state(“myPlugin”,数组(“id”=>“some-id”));
    594598
    595 $html_samples=数组(
    596 '<div data-wp-bind--id=“myPlugin::state.id”>内部内容</div></div>',
    597 '<div data-wp-bind--id=“myPlugin::state.id”>内部内容</div><div>',
    598 '<div><div data-wp-bind--id=“myPlugin::state.id”>内部内容</div>',
    599 '</div><div data-wp-bind--id=“myPlugin::state.id”>内部内容</div>',
    600 '<div data-wp-bind--id=“myPlugin::state.id”>内部<div>内容</div>',
    601 '<div data-wp-bind--id=“myPlugin::state.id”>内部</div>内容</div>',
    602 '<div data-wp-bind--id=“myPlugin::state.id”><span>内部内容</div>',
    603 '<div data-wp-bind--id=“myPlugin::state.id”>内部内容</div></span>',
    604 '<div data-wp-bind--id=“myPlugin::state.id”><span>内部内容</div></span>',
    605 '<div data-wp-bind--id=“myPlugin::state.id”>内部连接</></div>',
    606         );
    607 
    608 foreach($html_samples作为$html){
    609 $processed_html=$this->interactivity->process_directives($html);
    610 $p=新的WP_HTML_Tag_Processor($processed_HTML);
    611 $p->next_tag();
    612 $this->assertNull($p->get_attribute('id'));
    613         }
     599$processed_html=$this->interactivity->process_directives($html);
     600$p=新的WP_HTML_Tag_Processor($processed_HTML);
     601$p->next_tag();
     602$this->assertNull($p->get_attribute('id'));
     603    }
     604
     605    /**
     606*数据提供商。
     607     *
     608*@返回数组[]。
     609     */
     610公共静态函数data_html_with_unbalanced_tags(){
     611返回数组(
     612'DIV closer after'=>数组('<DIV data-wp-bind--id=“myPlugin::state.id”>内部内容</DIV></DIV>'),
     613'DIV opener after'=>array('<DIV data-wp-bind--id=“myPlugin::state.id”>内部内容</DIV><DIV>'),
     614'DIV opener before'=>数组('<DIV><DIV data-wp-bind--id=“myPlugin::state.id”>内部内容</DIV>'),
     615'DIV closer before'=>数组('</DIV><DIV data-wp-bind--id=“myPlugin::state.id”>内部内容</DIV>),
     616'DIV opener inhere'=>数组('<DIV data-wp-bind--id=“myPlugin::state.id”>内部<DIV>内容</DIV>'),
     617'DIV closer inside'=>数组('<DIV data-wp-bind--id=“myPlugin::state.id”>内部</DIV>内容</DIV>'),
     618“SPAN opener inside”=>数组('<div data-wp-bind--id=“myPlugin::state.id”><SPAN>内部内容</div>'),
     619'SPAN closer after'=>array('<div data-wp-bind--id=“myPlugin::state.id”>内部内容</div></SPAN>'),
     620'SPAN重叠'=>数组('<div data wp-bind--id=“myPlugin::state.id”><SPAN>内部内容</div></SPAN>'),
     621        );
    614622    }
    615623
注:请参见TracChangeset(跟踪变更集)获取有关使用变更集查看器的帮助。