# 千位分隔符 silently 破坏了设置中的输入值

**URL:** https://meta.discourse.org/t/thousand-separator-silently-ruins-inputted-value-in-settings/279977
**Category:** Bug
**Tags:** fixed
**Created:** [2023年九月25日 10:33 UTC](https://meta.discourse.org/t/thousand-separator-silently-ruins-inputted-value-in-settings/279977 "2023-09-25T10:33:41Z")
**Posts on this page:** 11
**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: [2023年九月25日 10:33 UTC](https://meta.discourse.org/t/thousand-separator-silently-ruins-inputted-value-in-settings/279977/1 "2023-09-25T10:33:41Z")

</div>

前方有恐怖故事。

一位社区经理联系我们，因为他们发现论坛用户数量的增长不如以往。

经过一些研究，我们发现许多刚注册的用户被视为不活跃而被删除。

结果发现是因为设置 `clean_up_inactive_users_after_days` 被设置为 1 😱

所以我点击了历史记录图标，发现该设置在一年前从 **730** （两年）更改为 **1,095** （三年）。

是的，各位，当你在数字站点设置中输入逗号（或点，如非英语国家常见）作为数字分组分隔符时，它将\*\*默默地(!)\*\*截断第一个分隔符之后的所有内容。更糟糕的是，这只有在硬刷新页面后才会显示。

---

<div class="post-metadata">

### Author: ![Lilly](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lilly/32/575047_2.png) [@Lilly](https://meta.discourse.org/u/Lilly)
#### Post date: [2023年九月25日 13:03 UTC](https://meta.discourse.org/t/thousand-separator-silently-ruins-inputted-value-in-settings/279977/3 "2023-09-25T13:03:27Z")

</div>

我想知道其他使用高数值的设置是否也受到这种影响？🤔

---

<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: [2023年九月25日 14:44 UTC](https://meta.discourse.org/t/thousand-separator-silently-ruins-inputted-value-in-settings/279977/4 "2023-09-25T14:44:39Z")

</div>

是的。  
_所有_数字设置都受到影响，并且有很多天、分钟和通用的高值设置

```plaintext
imap_polling_old_emails:1000
decompressed_theme_max_file_size_mb:1000
topic_views_heat_low:1000
secure_uploads_max_email_embed_image_size_kb:1024
maximum_session_age:1440
post_edit_time_limit:1440
composer_media_optimization_image_resize_dimensions_threshold:1920
composer_media_optimization_image_resize_width_target:1920
max_bookmarks_per_user:2000
topic_views_heat_medium:2000
default_other_new_topic_duration_minutes:2880
polling_interval:3000
topic_views_heat_high:3500
max_image_size_kb:4096
max_attachment_size_kb:4096
min_topic_views_for_delete_confirm:5000
max_form_template_content_length:5000
invite_link_max_redemptions_limit:5000
sitemap_page_size:10000
max_notifications_per_user:10000
short_progress_text_threshold:10000
auto_close_topics_post_count:10000
max_drafts_per_user:10000
anonymous_account_duration_minutes:10080
default_email_digest_frequency:10080
tl3_requires_posts_read_cap:20000
anon_polling_interval:25000
max_post_length:32000
tl2_post_edit_time_limit:43200
max_export_file_size_kb:50000
max_bulk_invites:50000
background_polling_interval:60000
decompressed_backup_max_file_size_mb:100000
search_enable_recent_regular_posts_offset_size:200000
default_other_auto_track_topics_after_msecs:300000
max_draft_length:400000
composer_media_optimization_image_bytes_optimization_threshold:524288

suggested_topics_unread_max_days_old:
suggested_topics_max_days_old:
pending_users_reminder_delay_minutes:
invite_expiry_days:
purge_unactivated_users_grace_period_days:
anonymous_account_duration_minutes:
ignored_users_message_gap_days:
clean_up_inactive_users_after_days:
clean_up_unused_staged_users_after_days:
show_time_gap_days:
old_post_notice_days:
returning_users_days:
suppress_digest_email_after_days:
disallow_reply_by_email_after_days:
delete_email_logs_after_days:
reset_bounce_score_after_days:
delete_rejected_email_after_days:
purge_deleted_uploads_grace_period_days:
tl2_requires_days_visited:
tl3_requires_days_visited:
invalidate_inactive_admin_email_after_days:
send_old_credential_reminder_days:
search_query_log_max_retention_days:
cold_age_days_low:
cold_age_days_medium:
cold_age_days_high:
delete_drafts_older_than_n_days:
delete_merged_stub_topics_after_days:
default_other_new_topic_duration_minutes:
retain_web_hook_events_period_days:
revoke_api_keys_unused_days:
revoke_api_keys_maxlife_days:
revoke_user_api_keys_unused_days:
revoke_user_api_keys_maxlife_days:

```

---

<div class="post-metadata">

### Author: ![ted](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ted/32/283882_2.png) [@ted](https://meta.discourse.org/u/ted)
#### Post date: [2023年十月10日 15:49 UTC](https://meta.discourse.org/t/thousand-separator-silently-ruins-inputted-value-in-settings/279977/6 "2023-10-10T15:49:05Z")

</div>

感谢您的报告，@RGJ！ 🙏

这确实是一个令人担忧的问题。我们通过以下方式在此处进行了修复：1) 仅允许在用户界面中输入数字，以及 2) 在后端删除任何非数字字符以增加安全性。

> <https://github.com/discourse/discourse/pull/23816>
>
> \### What is this change?
> 
> Currently, if you set an integer site setting in the… admin interface and include thousands separators, you will silently configure the wrong value.
> 
> \*\*Example:\*\*
> 
> \`\`\`
> 1,000 == 1
> 1.000 == 1
> 1 000 == 1
> \`\`\`
> 
> This PR replaces \`TextField\` inputs for integer site settings with \`NumberField\`.
> 
> It also cleans the numeric input of any non-digits in the backend in case any separators make it through.
> 
> \### Not in this PR
> 
> \- The actual value that is set in the back-end is not sent back to the front-end. We probably should.
> \- We should probably change the latter to use \[native number input\](https://caniuse.com/input-number) in a separate PR.
> \- The \`SiteSettingsController#update\` method is pretty big. I'm considering extracting the logic into a Ruby object that can be tested in isolation, but not in this PR.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [2023年十月13日 00:45 UTC](https://meta.discourse.org/t/thousand-separator-silently-ruins-inputted-value-in-settings/279977/7 "2023-10-13T00:45:07Z")

</div>



---

<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年六月20日 13:01 UTC](https://meta.discourse.org/t/thousand-separator-silently-ruins-inputted-value-in-settings/279977/8 "2024-06-20T13:01:59Z")

</div>



---

<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年六月20日 13:04 UTC](https://meta.discourse.org/t/thousand-separator-silently-ruins-inputted-value-in-settings/279977/9 "2024-06-20T13:04:36Z")

</div>

重新打开此问题，似乎情况有所倒退，甚至变得更糟。

- 转到 管理 --\>\> 设置 --\>\> 基本设置 --\>\> `建议主题`

Firefox 桌面版

- 输入 5.0 然后保存（无错误）并刷新 --\>\> 发现它已设置为 50
- 输入 5,0 然后保存（无错误）并刷新 --\>\> 发现它已设置为 0

Safari iOS 版

- 输入 5.0 然后保存（无错误）并刷新 --\>\> 发现它已设置为 50
- 输入 5,0 然后保存（无错误）并刷新 --\>\> 发现它已设置为 50

---

<div class="post-metadata">

### Author: ![Lilly](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lilly/32/575047_2.png) [@Lilly](https://meta.discourse.org/u/Lilly)
#### Post date: [2024年六月20日 13:39 UTC](https://meta.discourse.org/t/thousand-separator-silently-ruins-inputted-value-in-settings/279977/11 "2024-06-20T13:39:43Z")

</div>

感谢 Richard 的报告，我绝对可以重现此问题。

---

<div class="post-metadata">

### Author: ![tobiaseigen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tobiaseigen/32/539204_2.png) [@tobiaseigen](https://meta.discourse.org/u/tobiaseigen)
#### Post date: [2024年六月20日 14:19 UTC](https://meta.discourse.org/t/thousand-separator-silently-ruins-inputted-value-in-settings/279977/12 "2024-06-20T14:19:29Z")

</div>

感谢您的报告，理查德！我也能重现您所描述的情况。截至今天，这一切都是“按设计”进行的，但火狐浏览器中 `5,0` 结果为 `0` 是一个 bug。这真奇怪。

看起来我们确实需要重新审视一下这个问题，至少要更新管理员看到的内容，使其准确，并且不包含分隔符。目前，您必须在保存更改后刷新您的网页浏览器才能看到它。

但我认为我们还可以做更多工作来帮助管理员避免犯这些错误，并避免他们感到困惑。在我看来，您可以在 `suggested topics max days old`（建议主题的最大天数）字段中输入“364.5 天”，结果却变成了 3645 天，这似乎是错误的。也许我们干脆不允许在这些类型的字段中输入非数字字符。

---

<div class="post-metadata">

### Author: ![tobiaseigen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tobiaseigen/32/539204_2.png) [@tobiaseigen](https://meta.discourse.org/u/tobiaseigen)
#### Post date: [2024年七月8日 18:50 UTC](https://meta.discourse.org/t/thousand-separator-silently-ruins-inputted-value-in-settings/279977/15 "2024-07-08T18:50:48Z")

</div>

已在 [FIX: Do not allow , or . in site setting integer input by martin-brennan · Pull Request #27618 · discourse/discourse · GitHub](https://github.com/discourse/discourse/pull/27618) 中修复。现在这些字段只能输入数字，不能再输入 `,` 或 `.` 分隔符。

> 我们之前仅在服务器端对整数站点设置进行输入清理，这有点令人困惑，因为当用户输入例如 100.5 时，最终会得到 1005，并且在 UI 中看不到此反映。
> 
> 现在我们为这些设置使用了原生的数字输入，通过不允许在输入中使用 `.` 或 `,` 来改善体验，因为它们应该是整数，并且添加了 1 的步长。所有其他字符都已在此原生数字输入中被阻止。

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [2024年七月11日 20:03 UTC](https://meta.discourse.org/t/thousand-separator-silently-ruins-inputted-value-in-settings/279977/18 "2024-07-11T20:03:29Z")

</div>

此主题已在 3 天后自动关闭。不再允许回复。
