Unicode ユーザー名とグループ名

ユーザー名で許可する文字の制限を解除することは、最も古い機能リクエストの一つです。Discourse 2.3.0.beta9 以降、ユーザー名やグループ名内で Unicode 文字を使用できるようになりました。

新しいサイト設定

2 つの新しいサイト設定が追加されました:allowed unicode username characters(許可する Unicode ユーザー名文字)と unicode usernames(Unicode ユーザー名)。

allowed unicode username characters 設定では、特定の Unicode 文字のみを許可できます(例:[äöüßÄÖÜẞ]\p{Greek})。デフォルトでは、Discourse は文字(Ll / Lm / Lo / Lt / Lu)、記号(Mc, Me, Mn)、および数字(Nd, Nl、ただし No は除く)を許可します。この設定で許可される文字を制限することはできますが、追加の文字を許可することはできません。また、ASCII 文字や数字を禁止することもできません。

コミュニティのニーズに合わせて調整し、コミュニティで使用されている言語に必要な文字とスクリプトのみを許可してください。

正規表現における 文字クラス文字プロパティ について詳しく知りたい場合は、Ruby のドキュメントをご覧ください。

unicode usernames はデフォルトで無効化されており、ホモグラフユーザー名のなりすまし を防ぐために、これを有効にする前に必ず allowed unicode username characters 設定を構成することを強く推奨します。

許可される値の例:

  • zh_CN 中国語:[\p{Han}]
  • zh_TW 中国語:[\p{Han}]
  • ko 韓国語のみ:[\p{Hangul}]
  • jp 日本語:[\p{Han}\p{Katakana}\p{Hiragana}]
  • jp 日本語(カタカナのみ):[\p{Katakana}]
  • fi フィンランド語:[åäöÅÄÖ]
  • cs チェコ語:[ěščřžýáíéóůúďťň]

Letter Avatar サービス

Letter Avatar サービスが更新され、最も一般的に使用されるスクリプトでのアバター生成に対応しました。お使いの言語でアバターが表示されない場合は、Google Noto Fonts ファミリーからフォントを追加するための GitHub 上のプルリクエスト を作成してください。

unicode usernames を有効化できるのは、external system avatars enabled(外部システムアバターの有効化)サイト設定が有効になっている場合のみです。内部のアバタージェネレーターは Unicode をサポートしていないためです。外部サービスに依存したくない、またはできない場合は、Letter Avatar サービス の独自のインスタンスを運用することもできます。

さらに、5 月に Unicode に追加されたばかりの「令和」(Reiwa) の新しいグリフもサポートしています。

知っておくべきこと…

Discourse は、ユーザー名の長さ(min username length および max username length サイト設定)を検証する際、Unicode コードポイントではなく グラフエムクラスター(「ユーザーが認識する文字」) をカウントします。Letter Avatar サービスも、アバターを生成する際にユーザー名の最初のグラフエムクラスターを使用します。

また、reserved usernames(予約済みユーザー名)サイト設定もご確認ください。フォーラムがユーザー名で Unicode をサポートするようになった今、追加のユーザー名を登録しておくと良いでしょう。

フィードバック

コミュニティで Unicode ユーザー名を有効にしましたか?フィードバックをお聞かせください。
また、Discourse がサポートする各ロケールに対して、unicode username character whitelist(Unicode ユーザー名文字のホワイトリスト)の適切なデフォルト値を提供したいと考えています。正規表現の提案を返信にてお気軽にお寄せください。

「いいね!」 41

Thanks for the new feature!

I do have a discourse instance running for Chinese users, and I would like to test it.

But we have installed another plugin discourse-username-localization because previously unicode usernames were not supported officially.

So I would like to know how could I disable that plugin and switch to the official solution, will it break something? Any recommended steps to follow?

If this can be done, I think every CJK instance will switch to our official solution and contribute whitelist immediately :grinning:

「いいね!」 5

It looks like the plugin also changes the behavior for linking to CJK tags and categories. This will probably break, but we should fix it in Discourse core. That should be easy to fix.

Other than that disabling the plugin and enabling the official Unicode support should work without problems. Letter avatars will look differently afterwards, because the plugin currently converts Chinese usernames into latin characters. But I guess that’s a good thing. :slight_smile:

「いいね!」 9

Thanks.

I ‘ll create a branch with those not implemented yet left and try the official solution so they may not conflict.

The tags and categories uses the same set of regex but in javascript which doesn’t support \p{Katakana} stuff. I raised an issue to unify regex in that plugin, but the attempt failed. is it possible to use the same whitelist in the official implementation? eg a converter to convert ruby whitelist to javascript.

And the unicode avatar is just excellent!

「いいね!」 6

I just switched my forum to unicode username.

I updated discourse-username-localization to remove all the ruby stuff. (can’t wait to see you guys fix hashtags and mentions in the core, so I can abandon it completely)

And use this whitelist:

[\p{Han}\p{Katakana}\p{Hiragana}\p{Hangul}]

And update letter_avatar service to v4.

Now it works

「いいね!」 5

I think mentions are already supported :thinking:

「いいね!」 3

For Finnish, it should be [åäöÅÄÖ].

「いいね!」 4

Isn’t this your real Finnish name @rizka :wink:

「いいね!」 7

Not quite, I have just one of those in my surname. :slight_smile:

Å/å is actually not a pure Finnish language letter. It never appears anywhere except the Finnish alphabet, computer keyboards and names of Swedish people and places. Ö/ö is somewhat rare. Ä/ä is by far the most common, but for a reason unknown to me, very uncommon in Finnish first names. Appears in many surnames, though, like mine. :slight_smile:

「いいね!」 7

@marguerite You should also remove mentions.js.es6 from the plugin. There’s no need to patch anything related to usernames anymore. Only your customizations for categories and tags might still be needed, but we will fix that as well.

The +? at the end of the regex isn’t needed.
Out of curiosity: Can this whitelist be used for both zh_CN and zh_TW or is there a difference?

「いいね!」 6

@gerhard

I removed mentions.js.es6, do I need to remove override-username-match.js.es6 as well?

\p{Han} covers traditional and simplified Chinese. My whitelist will allow CJK usernames

「いいね!」 2

For EU langs it might be easiest to just allow all extended latin if possible, rather than hand-picking specific letters for every language. :slight_smile:

EDIT: Although reading a bit more about homograph attack, might not be the best idea after all. :blush:
Here are chars for Czech;

ěščřžýáíéóůúďťň

「いいね!」 8

Yes, you can remove that as well. Looks like that part of the plugin is broken anyway. User cards were refactored about a year ago.

「いいね!」 4

Katakana and Hiragana are both Japanese. Hangul is Korean.

I love this work. And I think a default setting below should work:

  • zh_CN, zh_TW: \p{Han}. This covers Chinese characters. Some communities can use more other characters. Maybe not default.
  • ko: \p{Hangul}. Korean don’t write Chinese at all. (I heard there are some Chinese characters in use in Korean?)
  • jp: [\p{Han}\p{Katakana}\p{Hiragana}] Japanese use all of them.

And maybe it’s good to mention reserved_usernames :sweat_smile:Unicode username does enable more names to be fake as admin/moderator.

「いいね!」 9

Thanks for the regular expressions and also for the tip regarding reserved usernames. I added a note in the first post.

「いいね!」 5

How does this option affect migrations? I am migrating from Kunena with a script based on the “official” kunena3.rb script.

I have a user called abd-def (for example). It gets imported as abcdef.

Then I turned on this option for the unicode usernames and deleted that user, and re-ran the script. It was again imported as abddef :frowning:

How can I ensure my user names with dashes don’t get changed during import?

Thanks!

The removal of the dash has nothing to do with Unicode usernames. That’s happening because the import script manipulates the username during the import.

I don’t think there’s any need for that. Try replacing those lines with the following code snippet. It should work.

@users[u['id'].to_i] = { id: u['id'].to_i, username: u['username'], email: u['email'], created_at: u['registerDate'] }
「いいね!」 7

Unicode ユーザー名およびグループ名のサポートが追加されたことを嬉しく思います :+1:

しかし、Unicode ユーザー名のサポートが導入されたことで、少し奇妙な状況が生じています。Discourse は 中国ไทย のようなユーザー名をサポートできるようになりましたが、-dashing- のような名前はサポートしていません。これは、最初の文字と最後の文字が英字、数字、またはアンダースコアである必要があるためです(ダッシュは含まれません)。

ダッシュ文字のサポートを追加するために Unicode 設定を試してみましたが、うまくいきませんでした(何か見落としている可能性はあります)。

Unicode がサポートされるようになった今、最初の文字と最後の文字に関するこのダッシュの規則を見直すことは意味があるでしょうか?なぜ、非 ASCII 文字(アンダースコアを含む)は許可されているのに、最初の文字と最後の文字でダッシュを許可しないのでしょうか?ダッシュは URL での特別なエンコーディングを必要としないようですが、他に理由があるのでしょうか?

これはトピックから少し逸れるかもしれませんが、別スレッドを立てるべきかどうかご意見をお聞かせください。

@gerhard ユーザー名は次のようにできますか?

discource__
または
discource_name

うまくいかないようです!

TIA

reserved_usernamesサイト設定を参照してください。

「いいね!」 1