Nombres de usuario y nombres de grupo en Unicode

Levantar las restricciones sobre los caracteres permitidos en los nombres de usuario es una de las solicitudes de funciones más antiguas. A partir de Discourse 2.3.0.beta9, finalmente es posible utilizar caracteres Unicode dentro de los nombres de usuario y de los grupos.

Nuevas configuraciones del sitio

Hay dos nuevas configuraciones del sitio: allowed unicode username characters (caracteres Unicode permitidos para nombres de usuario) y unicode usernames (nombres de usuario Unicode).

allowed unicode username characters te permite permitir solo ciertos caracteres Unicode (por ejemplo, [äöüßÄÖÜẞ] o \p{Greek}). De forma predeterminada, Discourse permite letras (Ll / Lm / Lo / Lt / Lu), marcas (Mc, Me, Mn) y números (Nd, Nl), pero no No. Esta configuración puede restringir esos caracteres, pero no es posible permitir caracteres adicionales. Además, no es posible prohibir las letras y los números ASCII.

Debes adaptarlo a las necesidades de tu comunidad y permitir solo los caracteres y scripts necesarios para los idiomas utilizados por tu comunidad.

Consulta la documentación de Ruby si deseas saber más sobre clases de caracteres y propiedades de caracteres en expresiones regulares.

unicode usernames está deshabilitado de forma predeterminada y te aconsejamos encarecidamente que configures la opción allowed unicode username characters antes de habilitarla, con el fin de evitar el suplantación de identidad de nombres de usuario homógrafos.

Valores permitidos de ejemplo:

  • zh_CN Chino: [\p{Han}]
  • zh_TW Chino: [\p{Han}]
  • ko Solo coreano: [\p{Hangul}]
  • jp Japonés: [\p{Han}\p{Katakana}\p{Hiragana}]
  • jp Japonés (solo カタカナ): [\p{Katakana}]
  • fi Finlandés: [åäöÅÄÖ]
  • cs Checo: [ěščřžýáíéóůúďťň]

Servicio de avatares de letra

El Servicio de Avatares de Letra se ha actualizado y hemos añadido soporte para generar avatares con los scripts más utilizados. Siéntete libre de crear una solicitud de extracción en GitHub para añadir una fuente de la familia Google Noto Fonts si encuentras avatares faltantes para tu idioma.

Habilitar unicode usernames solo es posible cuando la configuración del sitio external system avatars enabled (avatares de sistema externos habilitados) está activada, ya que el generador de avatares interno no admite Unicode. Puedes ejecutar tu propia instancia del Servicio de Avatares de Letra si no puedes o no quieres depender del servicio externo.

Incluso soportamos el glifo totalmente nuevo para “令和” (Reiwa) que se añadió a Unicode en mayo.

Buenas prácticas a tener en cuenta…

Discourse cuenta clústeres de grafemas (“caracteres percibidos por el usuario”) en lugar de puntos de código Unicode al validar la longitud del nombre de usuario (configuraciones del sitio min username length y max username length). El Servicio de Avatares de Letra también utiliza el primer clúster de grafemas de un nombre de usuario para generar un avatar.

También deberías echar un vistazo a la configuración del sitio reserved usernames (nombres de usuario reservados). Es posible que quieras añadir nombres de usuario adicionales ahora que tu foro admite Unicode en los nombres de usuario.

Comentarios

¿Has habilitado los nombres de usuario Unicode para tu comunidad? Nos gustaría conocer tus comentarios.
Además, queremos incluir valores predeterminados sensatos para la unicode username character whitelist (lista blanca de caracteres de nombre de usuario Unicode) para cada idioma compatible con Discourse. Siéntete libre de sugerir expresiones regulares en una respuesta.

41 Me gusta

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 Me gusta

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 Me gusta

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 Me gusta

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 Me gusta

I think mentions are already supported :thinking:

3 Me gusta

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

4 Me gusta

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

7 Me gusta

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 Me gusta

@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 Me gusta

@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 Me gusta

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 Me gusta

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 Me gusta

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 Me gusta

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

5 Me gusta

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 Me gusta

Me alegra ver el apoyo a nombres de usuario y de grupo Unicode :+1:.

Sin embargo, con la introducción del soporte para nombres de usuario Unicode, ahora hay una situación un poco extraña: Discourse puede aceptar algo como 中国 o ไทย como nombre de usuario, pero no -dashing-, ya que sigue requiriendo que el primer y último carácter sean una letra, un número o un guion bajo (pero no un guion).

Intenté usar la configuración de soporte Unicode para añadir soporte al carácter guion, pero eso no pareció funcionar para mí, aunque es posible que haya pasado por alto algo.

¿Tendría sentido revisar esta regla sobre el primer y último carácter en relación con el guion ahora que se admite Unicode? ¿Existe alguna razón para seguir no permitiendo el guion en la primera y última posición, pero sí cualquier letra no ASCII (incluido el guion bajo)? El guion no parece requerir codificación especial en las URL, pero ¿quizás haya otra razón para esto?

Sé que esto se desvía un poco del tema principal, así que avísame si debería abrir un nuevo hilo.

@gerhard ¿Puede un nombre de usuario ser así?

discource__
o
discource_name
?

¡Porque no parece que funcione!

Gracias de antemano.

Ver la configuración del sitio reserved_usernames.

1 me gusta