"解析为 "<!--? ?-->"?-6ren"> "解析为 "<!--? ?-->"?-我有一个包含以下 HTML 代码的文件: Curl 返回正常响应: $ curl file:///path/to/the/file.html 但是当我使用 Firefox 69 或 Chrome -6ren">
gpt4 book ai didi

html - 为什么浏览器将 ""解析为 "<!--? ?-->"?

转载 作者:搜寻专家 更新时间:2023-10-31 08:06:51 25 4
gpt4 key购买 nike

我有一个包含以下 HTML 代码的文件:

<p><? comment ?></p>

Curl 返回正常响应:

$ curl file:///path/to/the/file.html
<p><? comment ?></p>

但是当我使用 Firefox 69 或 Chrome 77 解析该响应时,没有任何显示给我,因为 HTML 代码如下:

<html><head></head><body><p><!--? comment ?--></p></body></html>

我觉得很奇怪。为什么会这样?

谢谢。

最佳答案

这是 HTML 标记化规则的一部分。

<字符使您的浏览器输入 tag-open-state .

12.2.5.6 Tag open state

Consume the next input character:

  • U+0021 EXCLAMATION MARK (!)
    • Switch to the markup declaration open state.
  • U+002F SOLIDUS (/)
    • Switch to the end tag open state.
  • ASCII alpha
    • Create a new start tag token, set its tag name to the empty string. Reconsume in the tag name state.
  • U+003F QUESTION MARK (?)
  • ...

所以你的 ?字符作为已知错误处理,然后解析器切换到 bogus comment state , 这会将所有内容放到下一个 > 之前注释标记中的字符。

关于html - 为什么浏览器将 "<? ?>"解析为 "&lt;!--? ?-->"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58268535/

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