在 HTML 中可以有多少个嵌套标签才会导致浏览器崩溃?

发布于 2024-09-11 23:32:01 字数 539 浏览 2 评论 0原文

今天早些时候我有一个关于嵌套 HTML 标签以及浏览器如何渲染它们的想法:

<html xmlns="http://www.w3.org/1999/xhtml" {or whichever html version} xml:lang="en" lang="en">
<head>
</head>
<body>

let n = 1

<div>

递归 div n 次,直到最大(浏览器失败)

</div>
</body>
</html>

n 当浏览器无法处理更多递归时?

我认为这对于每个浏览器来说都是不同的,对于移动应用程序来说也是不同的。是否有网络标准,例如域名的最大长度为 127 个字符?

我从来没有遇到过这个问题,但我很好奇什么时候会遇到。

I had a thought earlier today regarding nested HTML tags and how browsers render them:

<html xmlns="http://www.w3.org/1999/xhtml" {or whichever html version} xml:lang="en" lang="en">
<head>
</head>
<body>

let n = 1

<div>

recurse div n times until maximum (browser fails)

</div>
</body>
</html>

what will n be when the browser cannot handle any more recursion?

I would think this would be different for each browser, and different also for mobile apps. Is there a web standard, such as the maximum 127 character length for domain names?

I have never run into this problem, but I am curious when it would.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

猫性小仙女 2024-09-18 23:32:01

没有要求最大嵌套的标准,因此这完全是特定于实现的。

有可能在崩溃之前,浏览器会变得无法使用(速度变慢等)。

如果您很好奇,您可以对此进行基准测试 - 编写一个生成嵌套标签的应用程序,并查看每个浏览器何时崩溃:)

There is no standard requiring a maximum nesting, so this will be entirely implementation specific.

Chances are that before crashing, the browser would become unusable (slow downs etc).

If you are very curious, you can benchmark this - code an application that generates nested tags and see when each browser crashes on you :)

只有一腔孤勇 2024-09-18 23:32:01

你担心太多了。或者你正在计划一个太复杂的布局。即便如此,如果不是特意创建的 HTML,您也不太可能达到这样的限制。

如果浏览器的 HTML 解析器是递归的,那么在输入深度嵌套的标签时,它可能会因为堆栈溢出而崩溃。但在现代系统/操作系统上,堆栈默认情况下足够大,可以支持一百级或更多级别的递归,具体取决于堆栈分配变量的大小。

如果解析器不是递归的,那么当给定一个极其复杂(难以置信的大令人难以置信的深度嵌套)文档时,我的下一个赌注将是OutOfMemoryError。

You worry too much. Or you're planning a waaay too complicated layout. And even then, it's very unlikely you will every reach such a limit with HTML not deliberately created to do so.

If the browser's HTML parser is recursive, it might crash when fed deeply-nested tags simply because the stack overflows. But on modern systems/OSs, the stack is by default large enough to support a hundred or more of levels of recursion, depending on the size of stack-allocated variables.

If the parser isn't recursive, my next bet would be an OutOfMemoryError when given an extremely complex (incredibly large and incredibly deeply nested) document.

自我难过 2024-09-18 23:32:01

Firefox 似乎(似乎?)在这方面存在一些问题。

请参阅 https://groups.google.com/forum/# !topic/mozilla.dev.platform/SUknMzK1ZAc

特别是,Firefox 将深度限制为 200 个元素。

There seems (seemed?) to be some issues with Firefox regarding this.

See https://groups.google.com/forum/#!topic/mozilla.dev.platform/SUknMzK1ZAc

Particulary, Firefox limit(ed?) the deep to 200 elements.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文