# "标题最大字数"值过大导致服务器错误

**URL:** https://meta.discourse.org/t/large-value-for-title-max-word-length-causes-server-error/319656
**Category:** Bug
**Tags:** pr-welcome
**Created:** [2024年八月1日 15:03 UTC](https://meta.discourse.org/t/large-value-for-title-max-word-length-causes-server-error/319656 "2024-08-01T15:03:16Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### Post date: [2024年八月1日 15:03 UTC](https://meta.discourse.org/t/large-value-for-title-max-word-length-causes-server-error/319656/1 "2024-08-01T15:03:16Z")

</div>

- 将 `title max word length` 设置为 `2000000000`
- 尝试创建一个主题
- 收到 500 错误
- 无法创建主题

```plaintext
RegexpError (too big number for repeat range: /\\p{Alnum}{2000000001,}/)
lib/text_sentinel.rb:62:in `seems_unpretentious?'
lib/text_sentinel.rb:45:in `valid?'
lib/validators/quality_title_validator.rb:12:in `validate_each'
lib/topic_creator.rb:24:in `valid?'
lib/has_errors.rb:13:in `validate_child'
lib/post_creator.rb:133:in `valid?'
lib/post_creator.rb:187:in `create'
lib/new_post_manager.rb:318:in `perform_create_post'
lib/new_post_manager.rb:252:in `perform'
app/controllers/posts_controller.rb:215:in `create'

```

于[上周](https://github.com/discourse/discourse/commit/73ce3589adf2b859ac5991d65ab405f280dcd292)引入。最大值为[100000](https://github.com/search?q=repo%3Aruby%2Fruby%20ONIG_MAX_REPEAT_NUM&type=code)。

---

<div class="post-metadata">

### Author: ![mentalstring](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mentalstring/32/168934_2.png) [@mentalstring](https://meta.discourse.org/u/mentalstring)
#### Post date: [2024年八月2日 08:39 UTC](https://meta.discourse.org/t/large-value-for-title-max-word-length-causes-server-error/319656/3 "2024-08-02T08:39:06Z")

</div>

`最大主题标题长度`目前似乎限制在 255 个字符，那么 `标题最大单词长度` 是否也应该有这个限制呢？

 ![Screenshot 2024-08-02 at 09.23.51](https://global.discourse-cdn.com/meta/original/4X/1/d/5/1d5f11c54cdc7650b602b5ba0c606530a1fb3e65.png)

我曾想过可以通过将 `标题最大单词长度` 设置为 0（而不是使用一个非常高的值）来移除标题的最大单词长度限制，但这实际上暴露了一个单独的错误：它目前接受 0，但并没有禁用检查，反而导致无法创建主题，因为没有标题是有效的：

 ![Screenshot 2024-08-02 at 09.35.57](https://global.discourse-cdn.com/meta/original/4X/2/e/8/2e82f13f1706bf3b1f8ce4158af1ae72e429fd54.png)

当然，可以撤销暴露这个问题的提交，但无论如何，似乎 `标题最大单词长度` 需要一些验证（例如 [1, 255]）？

---

<div class="post-metadata">

### Author: ![mentalstring](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mentalstring/32/168934_2.png) [@mentalstring](https://meta.discourse.org/u/mentalstring)
#### Post date: [2024年八月7日 11:15 UTC](https://meta.discourse.org/t/large-value-for-title-max-word-length-causes-server-error/319656/4 "2024-08-07T11:15:29Z")

</div>

我尝试通过将 `title_max_word_length` 限制为 [1, 255] 来解决此问题。

> <https://github.com/discourse/discourse/pull/28217>
>
> This adds contraints to \`title\_max\_word\_length\` which otherwise could be arbitra…ry large or set to 0, which would effectively block topic creation. The max value is set to the max of \`max\_topic\_title\_length\` (255).
> 
> Related meta topic: https://meta.discourse.org/t/large-value-for-title-max-word-length-causes-server-error/319656

---

<div class="post-metadata">

### Author: ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### Post date: [2024年八月8日 06:28 UTC](https://meta.discourse.org/t/large-value-for-title-max-word-length-causes-server-error/319656/5 "2024-08-08T06:28:49Z")

</div>

鉴于人们可能已将其设置为 0 来尝试禁用检查，因此将值 0 迁移到 255 而不是 1 可能会更好，您怎么看？🤔

---

<div class="post-metadata">

### Author: ![mentalstring](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mentalstring/32/168934_2.png) [@mentalstring](https://meta.discourse.org/u/mentalstring)
#### Post date: [2024年八月8日 18:32 UTC](https://meta.discourse.org/t/large-value-for-title-max-word-length-causes-server-error/319656/6 "2024-08-08T18:32:25Z")

</div>

我并不反对……尽管我怀疑是否有任何论坛会无意中将其设置为 0，因为那样就无法创建任何主题了，所以它很可能已经被撤销了。

---

<div class="post-metadata">

### Author: ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### Post date: [2024年八月8日 20:20 UTC](https://meta.discourse.org/t/large-value-for-title-max-word-length-causes-server-error/319656/7 "2024-08-08T20:20:23Z")

</div>

你说得对！请忽略我的评论！
