Skip to content

Commit 510208b

Browse files
committed
ci(translator): address third round of CodeRabbit findings
- Surrogate-safe title truncation: .slice(0, 256) can split a UTF-16 surrogate pair (e.g. emoji at position 255), producing an invalid string; check whether char 255 is a high surrogate and back up by one if so - Scope duplicate-comment guard to github-actions[bot] author: any user could post the marker string manually and permanently block the translation; require the bot login as well as the marker
1 parent 0abc357 commit 510208b

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

‎.github/workflows/issue-translator.yml‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,12 @@ jobs:
9090
return;
9191
}
9292
93-
const title = (typeof parsed.translated_title === 'string'
94-
? parsed.translated_title.trim() : '').slice(0, 256); // GitHub title limit
93+
// Slice at 256 chars but avoid splitting a UTF-16 surrogate pair (e.g. emoji)
94+
const rawTitle = typeof parsed.translated_title === 'string'
95+
? parsed.translated_title.trim() : '';
96+
const title = rawTitle.length <= 256
97+
? rawTitle
98+
: rawTitle.slice(0, rawTitle[255] >= '\uD800' && rawTitle[255] <= '\uDBFF' ? 255 : 256);
9599
const body = typeof parsed.translated_body === 'string'
96100
? parsed.translated_body.trim() : '';
97101
const lang = typeof parsed.detected_language === 'string'
@@ -122,7 +126,7 @@ jobs:
122126
const comments = await github.paginate(github.rest.issues.listComments, {
123127
owner, repo, issue_number, per_page: 100,
124128
});
125-
if (comments.some(c => c.body?.includes(MARKER))) {
129+
if (comments.some(c => c.user?.login === 'github-actions[bot]' && c.body?.includes(MARKER))) {
126130
core.info('Translation comment already exists.');
127131
return;
128132
}

0 commit comments

Comments
 (0)