Limit script name (50), description (200), and tags (5) to prevent SEO keyword stuffing#1
Limit script name (50), description (200), and tags (5) to prevent SEO keyword stuffing#1
Conversation
Agent-Logs-Url: https://github.com/scriptscat/scriptlist/sessions/642555f0-cb22-4efb-9ec1-c6e96e9173e1 Co-authored-by: CodFrm <[email protected]>
|
如果是更新,name和description没有变的话,可以跳过,加上检查name是不是简单name,也禁止掉复杂的name,检查description是不是一句话,禁止复杂的描述 |
CodFrm
left a comment
There was a problem hiding this comment.
如果是更新,name和description没有变的话,可以跳过,加上检查name是不是简单name,也禁止掉复杂的name,检查description是不是一句话,禁止复杂的描述,加上单元测试
… add unit tests Agent-Logs-Url: https://github.com/scriptscat/scriptlist/sessions/31498497-724d-4fdf-bd6b-a99c166a2434 Co-authored-by: CodFrm <[email protected]>
Agent-Logs-Url: https://github.com/scriptscat/scriptlist/sessions/31498497-724d-4fdf-bd6b-a99c166a2434 Co-authored-by: CodFrm <[email protected]>
Done in commit db1ec35:
Done in commit db1ec35 — same changes as above. |
| // pre-date these limits can still be updated without forcing the author to rename them. | ||
| func validateScriptMeta(ctx context.Context, name, description string, tags []string, nameUnchanged, descUnchanged bool) error { | ||
| if !nameUnchanged { | ||
| if strings.ContainsAny(name, "\r\n") { |
There was a problem hiding this comment.
只是判断换行符太简单了,而且本来也就不允许换行,有没有库可以判断?需要支持i18n,描述也要如此。或者名字禁止标点符号之类,描述判断是不是一句话
There was a problem hiding this comment.
Updated in commit 5e02e37 with two compiled regex patterns (no extra dependencies needed, standard regexp package):
nameInvalidRe — rejects SEO keyword-list separators in names: commas (,/,), pipes (|), semicolons (;/;), and newlines. Pattern: [\r\n,,|;;]
multiSentenceRe — rejects descriptions with more than one sentence:
- Newlines (
[\r\n]) - Chinese sentence-enders (
[。!?]) followed by optional whitespace then any non-whitespace (covers both第一句。第二句and第一句。 第二句) - English sentence-enders (
[.!?]) followed by at least one space then a capital letter or CJK character (catchesFirst. Secondwithout false-positives onv1.0or URLs)
Pattern: [\r\n]|[。!?]\s*\S|[.!?]\s+[A-Z\x{4e00}-\x{9fa5}]
26 unit test cases covering all paths, each asserting the specific *httputils.Error code.
…nce check Agent-Logs-Url: https://github.com/scriptscat/scriptlist/sessions/756524d6-1521-49e7-9189-a45815cc1623 Co-authored-by: CodFrm <[email protected]>
…sentence test Agent-Logs-Url: https://github.com/scriptscat/scriptlist/sessions/756524d6-1521-49e7-9189-a45815cc1623 Co-authored-by: CodFrm <[email protected]>
Script authors were able to abuse name/description fields with excessive keywords for SEO. Tags had no practical limit. This enforces strict limits so names stay concise, descriptions stay to a single sentence, and additional categorization uses tags (capped at 5).
API binding constraints (library-type scripts)
name:max=128→max=50description:max=10240/102400→max=200tags:max=64→max=5Applies to
CreateRequest,UpdateCodeRequest,UpdateSettingRequest, andUpdateLibInfoRequest.Service-layer validation (userscripts)
For non-library scripts, name/description/tags come from parsed
@name/@description/@tagsmetadata headers in the script code — not from the API request body — so binding constraints alone are insufficient. AvalidateScriptMetahelper is added and called in bothCreateandUpdateCodeafter meta parsing:Name format check (
nameInvalidRe): rejects names containing SEO keyword-list separators — ASCII/Chinese commas (,/,), pipes (|), ASCII/Chinese semicolons (;/;), and newlines. This prevents patterns like"脚本名称,关键词1,关键词2"or"Script | keyword1 | keyword2".Description format check (
multiSentenceRe): rejects descriptions with more than one sentence:\r/\n)。!?) followed by optional whitespace then any non-whitespace character — catches both第一句。第二句and第一句。 第二句.!?) followed by at least one space then a capital letter or CJK character — catchesFirst. Secondwithout false-positives onv1.0or URLsSkip on unchanged: when
UpdateCodeis called and the parsed name/description matches what is already stored, length and format checks for that field are skipped. This allows existing scripts with values that pre-date these limits to continue being updated without forcing a rename.Note: system-generated tags (
后台脚本,定时脚本) are appended after validation and do not count toward the user's 5-tag limit.New error codes
ScriptNameTooLong,ScriptDescTooLong,ScriptTagsTooMany,ScriptNameInvalid,ScriptDescInvalidadded tointernal/pkg/code/with Chinese messages describing the new rules.Unit tests
26 test cases in
internal/service/script_svc/script_validate_test.gocovering all validation paths — including SEO separator rejection, Chinese/English multi-sentence detection, whitespace-separated sentence detection, length limits, skip-on-unchanged, and tag count — each asserting the specific*httputils.Errorcode returned.Original prompt