Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix(devs): @devs followed straight by Chinese, Japanese or Korean text is a bug report

AdityaUmale05d169d58f22
diff --git a/shared/devs-mention.test.ts b/shared/devs-mention.test.ts
index 167152baca..171e174194 100644
--- a/shared/devs-mention.test.ts
+++ b/shared/devs-mention.test.ts
@@ -23,6 +23,16 @@ describe("the @devs tag", () => {
expect(tagsDevs("@devs it broke", ["Dev"])).toBe(true);
});
+ it("ends where Chinese, Japanese or Korean text starts right after it, with no space", () => {
+ expect(tags("@devs总控坏了")).toEqual(["@devs"]);
+ expect(tags("@Devsボタンが動かない @devs버튼")).toEqual(["@Devs", "@devs"]);
+ expect(tags("@devs 总控坏了")).toEqual(["@devs"]);
+ expect(withoutDevsTags("@devs总控坏了")).toBe("总控坏了");
+ expect(tagsDevs("@devsé")).toBe(false);
+ expect(tagsDevs("@devs总控 坏了", ["devs总控"])).toBe(false);
+ expect(tagsDevs("@devs总控坏了", ["Devs"])).toBe(false);
+ });
+
it("leaves the person's own words without the tag", () => {
expect(withoutDevsTags("@devs the send button froze")).toBe("the send button froze");
expect(withoutDevsTags("@devs: pictures never load, @devs please")).toBe("pictures never load, please");
diff --git a/shared/devs-mention.ts b/shared/devs-mention.ts
index b7eb6396d7..e8bbf0decd 100644
--- a/shared/devs-mention.ts
+++ b/shared/devs-mention.ts
@@ -5,8 +5,15 @@ import { proseOnly } from "./person-mention.ts";
export const DEVS_TAG = "devs";
-const startsWithName = (rest: string, name: string) =>
- rest.slice(0, name.length).toLowerCase() === name.toLowerCase() && !isMentionNameContinuation(rest.slice(name.length));
+/** Chinese, Japanese and Korean are written without spaces, so "@devs总控坏了" ends the Latin tag at the first such
+ * character. Only the devs tag reads it this way; other names keep the shared word rule. */
+const CJK_START = /^[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}]/u;
+
+const startsWithName = (rest: string, name: string) => {
+ if (rest.slice(0, name.length).toLowerCase() !== name.toLowerCase()) return false;
+ const after = rest.slice(name.length);
+ return !isMentionNameContinuation(after) || (name.toLowerCase() === DEVS_TAG && CJK_START.test(after));
+};
/** The tag's length when `rest` (the text after an at-sign) starts with it. A bot or department named devs, or with a
* longer name that starts with it, is tagged instead. */