{"record":{"id":"316bb70b5cb86d40","repo":"OtterMind/Chat2DB","slug":"prepared-qq-notification-contains-control-characte","errorCode":null,"errorMessage":"Prepared QQ notification contains control characters","messagePattern":"Prepared QQ notification contains control characters","errorType":"validation","errorClass":"ConfigurationError","httpStatus":null,"severity":"error","filePath":"script/github/notify_qq.py","lineNumber":263,"sourceCode":"def _read_prepared_message(path: Path, repository: str) -> tuple[str, str]:\n    if not path.is_file() or path.stat().st_size > 4096:\n        raise ConfigurationError(\"Prepared QQ notification is missing or too large\")\n    try:\n        envelope = json.loads(path.read_text(encoding=\"utf-8\"))\n    except (OSError, UnicodeError, json.JSONDecodeError) as error:\n        raise ConfigurationError(\"Prepared QQ notification is not valid JSON\") from error\n    if not isinstance(envelope, Mapping) or envelope.get(\"version\") != 1:\n        raise ConfigurationError(\"Prepared QQ notification has an invalid format\")\n    if envelope.get(\"repository\") != repository:\n        raise ConfigurationError(\"Prepared QQ notification repository does not match\")\n    event_name = str(envelope.get(\"event_name\") or \"\")\n    if event_name not in COLLECTED_EVENT_NAMES:\n        raise ConfigurationError(\"Prepared QQ notification event is not allowed\")\n    message = envelope.get(\"message\")\n    if not isinstance(message, str) or not message or len(message) > 900:\n        raise ConfigurationError(\"Prepared QQ notification message is invalid\")\n    if re.search(r\"[\\x00-\\x08\\x0b\\x0c\\x0e-\\x1f\\x7f]\", message):\n        raise ConfigurationError(\"Prepared QQ notification contains control characters\")\n    if re.search(r\"(?i)\\[CQ:\", message):\n        raise ConfigurationError(\"Prepared QQ notification contains a OneBot CQ code\")\n    return event_name, message\n\n\ndef _event_detail(event_name: str, action: str, payload: Mapping[str, Any]) -> str:\n    if action in {\"labeled\", \"unlabeled\"}:\n        label = payload.get(\"label\") or {}\n        return f\"标签：{_clean_text(label.get('name'), 80)}\"\n    if action in {\"assigned\", \"unassigned\"}:\n        return f\"处理人：{_login(payload.get('assignee'))}\"\n    if action in {\"milestoned\", \"demilestoned\"}:\n        milestone = payload.get(\"milestone\") or {}\n        return f\"里程碑：{_clean_text(milestone.get('title'), 100)}\"\n    if action in {\"review_requested\", \"review_request_removed\"}:\n        reviewer = _login(payload.get(\"requested_reviewer\"))\n        team = payload.get(\"requested_team\") or {}\n        target = reviewer or _clean_text(team.get(\"name\"), 80)","sourceCodeStart":245,"sourceCodeEnd":281,"githubUrl":"https://github.com/OtterMind/Chat2DB/blob/5ee1e990e73fbcae1969dc554be254fedb3ab888/script/github/notify_qq.py#L245-L281","documentation":"Raised by _read_prepared_message (notify_qq.py:263) when message contains a C0 control character or DEL (\\x00-\\x08, \\x0b, \\x0c, \\x0e-\\x1f, \\x7f). OneBot/QQ group messages reject such bytes, and the live build path strips them via _clean_text, so the prepared envelope must already be clean.","triggerScenarios":"The envelope's message contains a raw control byte, e.g. a literal NUL, BEL, or vertical tab. Only reachable via QQ_PREPARED_MESSAGE_PATH because the writer sanitizes with _clean_text.","commonSituations":"Hand-editing or piping a binary/templated message into the envelope; an envelope produced by tooling that did not sanitize; copy-paste from a terminal that embeds escape sequences.","solutions":["Regenerate the envelope through the collect step, which runs _clean_text on every field.","Strip control characters from the message field: re.sub(r'[\\x00-\\x08\\x0b\\x0c\\x0e-\\x1f\\x7f]', '', message).","Discard the tampered artifact and re-run collect."],"exampleFix":"import re\nclean = re.sub(r'[\\x00-\\x08\\x0b\\x0c\\x0e-\\x1f\\x7f]', '', message)","handlingStrategy":"validation","validationCode":"import re\nif re.search(r'[\\x00-\\x08\\x0b\\x0c\\x0e-\\x1f\\x7f]', message):\n    message = re.sub(r'[\\x00-\\x08\\x0b\\x0c\\x0e-\\x1f\\x7f]', '', message)","typeGuard":"import re\nCONTROL = re.compile(r'[\\x00-\\x08\\x0b\\x0c\\x0e-\\x1f\\x7f]')\ndef is_clean_text(message: str) -> bool:\n    return not CONTROL.search(message)","tryCatchPattern":null,"preventionTips":["Always build messages with _clean_text, which strips control characters.","Never paste terminal/formatted text directly into the envelope."],"tags":["config","github-actions","notification","validation","sanitization"],"backgroundTag":null,"analyzedSha":"5ee1e990e73fbcae1969dc554be254fedb3ab888","analyzedAt":"2026-08-14T07:05:03.077Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}