Fix bug with how Emojibase wasn't stripping characters (#37442)
Some checks failed
Haml Linting / lint (push) Has been cancelled
JavaScript Linting / lint (push) Has been cancelled
Ruby Linting / lint (push) Has been cancelled
JavaScript Testing / test (push) Has been cancelled
Historical data migration test / test (14-alpine) (push) Has been cancelled
Historical data migration test / test (15-alpine) (push) Has been cancelled
Historical data migration test / test (16-alpine) (push) Has been cancelled
Historical data migration test / test (17-alpine) (push) Has been cancelled
Ruby Testing / build (production) (push) Has been cancelled
Bundler Audit / security (push) Has been cancelled
Check i18n / check-i18n (push) Has been cancelled
Chromatic / Check for relevant changes (push) Has been cancelled
CodeQL / Analyze (push) Has been cancelled
Check formatting / lint (push) Has been cancelled
Ruby Testing / build (test) (push) Has been cancelled
Chromatic / Run Chromatic (push) Has been cancelled
Ruby Testing / test (.ruby-version) (push) Has been cancelled
Ruby Testing / test (3.2) (push) Has been cancelled
Ruby Testing / test (3.3) (push) Has been cancelled
Ruby Testing / ImageMagick tests (push) Has been cancelled
Ruby Testing / End to End testing (push) Has been cancelled
Ruby Testing / Elastic Search integration testing (push) Has been cancelled

This commit is contained in:
Echo 2026-01-09 19:38:22 +01:00 committed by GitHub
parent b55982cc1a
commit a4b8b9fe98
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,8 +1,9 @@
import debug from 'debug';
import { fromUnicodeToHexcode } from 'emojibase';
import { emojiRegexPolyfill } from '@/mastodon/polyfills';
import { VARIATION_SELECTOR_CODE } from './constants';
export function emojiLogger(segment: string) {
return debug(`emojis:${segment}`);
}
@ -46,7 +47,24 @@ export function anyEmojiRegex() {
}
export function emojiToUnicodeHex(emoji: string): string {
return fromUnicodeToHexcode(emoji, false);
const codes: string[] = [];
for (const char of emoji) {
const code = char.codePointAt(0);
if (code !== undefined) {
codes.push(code.toString(16).toUpperCase().padStart(4, '0'));
}
}
// Handles how Emojibase removes the variation selector for single code emojis.
// See: https://emojibase.dev/docs/spec/#merged-variation-selectors
if (
codes.at(1) === VARIATION_SELECTOR_CODE.toString(16).toUpperCase() &&
codes.length === 2
) {
codes.pop();
}
return codes.join('-');
}
function supportsRegExpSets() {