# Unicode-gebruikersnaam met Σ als laatste teken leidt tot een fout bij het laden van de profielpagina

**URL:** https://meta.discourse.org/t/unicode-username-with-as-the-final-char-leads-to-an-error-loading-profile-page/173182
**Category:** Bug
**Created:** [13 december 2020 om 23:24 UTC](https://meta.discourse.org/t/unicode-username-with-as-the-final-char-leads-to-an-error-loading-profile-page/173182 "2020-12-13T23:24:31Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![chrispanag](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/chrispanag/32/105853_2.png) [@chrispanag](https://meta.discourse.org/u/chrispanag)
#### Post date: [13 december 2020 om 23:24 UTC](https://meta.discourse.org/t/unicode-username-with-as-the-final-char-leads-to-an-error-loading-profile-page/173182/1 "2020-12-13T23:24:31Z")

</div>

Can this also affect user related slugs? (containing the username)  
We have a few users that use UTF-8 usernames and some of them can’t access their profiles…

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [13 december 2020 om 23:27 UTC](https://meta.discourse.org/t/unicode-username-with-as-the-final-char-leads-to-an-error-loading-profile-page/173182/2 "2020-12-13T23:27:51Z")

</div>

It should not affect user at all as the routes are completely different.

Can you share a link where a profile fails to load? Or at least an example of a username that triggers the bug?

---

<div class="post-metadata">

### Author: ![chrispanag](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/chrispanag/32/105853_2.png) [@chrispanag](https://meta.discourse.org/u/chrispanag)
#### Post date: [13 december 2020 om 23:31 UTC](https://meta.discourse.org/t/unicode-username-with-as-the-final-char-leads-to-an-error-loading-profile-page/173182/3 "2020-12-13T23:31:18Z")

</div>

This is one case: [https://rembetiko.gr/u/σπυρος](https://rembetiko.gr/u/%CF%83%CF%80%CF%85%CF%81%CE%BF%CF%82)

The username is ΣΠΥΡΟΣ (which is the capital form of σπυρος)

* * *

Sorry for the greek 😅

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [13 december 2020 om 23:34 UTC](https://meta.discourse.org/t/unicode-username-with-as-the-final-char-leads-to-an-error-loading-profile-page/173182/4 "2020-12-13T23:34:56Z")

</div>

This page is behind a Cloudflare proxy? Can you test with that off?

Also what are the values of the settings:

- `allowed unicode username characters`

- `unicode usernames`

---

<div class="post-metadata">

### Author: ![chrispanag](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/chrispanag/32/105853_2.png) [@chrispanag](https://meta.discourse.org/u/chrispanag)
#### Post date: [13 december 2020 om 23:40 UTC](https://meta.discourse.org/t/unicode-username-with-as-the-final-char-leads-to-an-error-loading-profile-page/173182/5 "2020-12-13T23:40:14Z")

</div>

Here are the values (pretty standard 😅)

 ![image](https://global.discourse-cdn.com/meta/original/3X/3/1/313570d1ae14b5e8d0bcc7aba3a9cd50e035dbee.png)

> [@Falco](#):
>
> This page is behind a Cloudflare proxy?

Yes

> [@Falco](#):
>
> Can you test with that off?

I just disabled the proxy, and tested again. The issue unfortunately persists. I will keep the proxy disabled for a bit so that you can test it yourself if you want 🙂

* * *

Thank you very much for your help! 😃

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [14 december 2020 om 01:13 UTC](https://meta.discourse.org/t/unicode-username-with-as-the-final-char-leads-to-an-error-loading-profile-page/173182/6 "2020-12-14T01:13:01Z")

</div>

> [@chrispanag](#):
>
> The username is ΣΠΥΡΟΣ (which is the capital form of σπυρος)

Hmmm.

If I try to load the upper case it loads: [Προφίλ - ΣΠΥΡΟΣ - Ρεμπέτικο Φόρουμ](https://rembetiko.gr/u/%CE%A3%CE%A0%CE%A5%CE%A1%CE%9F%CE%A3) at first and then fails on a subsequent JSON fetch to the lowercase version.

Looks like an error between our upper/lower case handling.

---

<div class="post-metadata">

### Author: ![chrispanag](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/chrispanag/32/105853_2.png) [@chrispanag](https://meta.discourse.org/u/chrispanag)
#### Post date: [14 december 2020 om 09:23 UTC](https://meta.discourse.org/t/unicode-username-with-as-the-final-char-leads-to-an-error-loading-profile-page/173182/7 "2020-12-14T09:23:28Z")

</div>

Strangely this one works:  
[https://rembetiko.gr/u/αγγελικη\_ντοτη](https://rembetiko.gr/u/%CE%B1%CE%B3%CE%B3%CE%B5%CE%BB%CE%B9%CE%BA%CE%B7_%CE%BD%CF%84%CE%BF%CF%84%CE%B7)  
The username is ΑΓΓΕΛΙΚΗ\_ΝΤΟΤΗ (again capital form of αγγελικη\_ντοτη)

---

<div class="post-metadata">

### Author: ![chrispanag](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/chrispanag/32/105853_2.png) [@chrispanag](https://meta.discourse.org/u/chrispanag)
#### Post date: [16 december 2020 om 22:32 UTC](https://meta.discourse.org/t/unicode-username-with-as-the-final-char-leads-to-an-error-loading-profile-page/173182/8 "2020-12-16T22:32:15Z")

</div>

Could it be that in Greek, there are two ways to uncapitalize the letter ‘Σ’?

- ‘ς’ when it is used at the end of a word
- ‘σ’ anywhere else

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [16 december 2020 om 22:35 UTC](https://meta.discourse.org/t/unicode-username-with-as-the-final-char-leads-to-an-error-loading-profile-page/173182/9 "2020-12-16T22:35:02Z")

</div>

So is this wrong?

```plaintext
[1] pry(main)> "ΣΠΥΡΟΣ".downcase
=> "σπυροσ"

```

---

<div class="post-metadata">

### Author: ![chrispanag](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/chrispanag/32/105853_2.png) [@chrispanag](https://meta.discourse.org/u/chrispanag)
#### Post date: [16 december 2020 om 22:35 UTC](https://meta.discourse.org/t/unicode-username-with-as-the-final-char-leads-to-an-error-loading-profile-page/173182/10 "2020-12-16T22:35:57Z")

</div>

Yes, grammatically it is wrong. The correct form should be “Spiros”

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [16 december 2020 om 22:47 UTC](https://meta.discourse.org/t/unicode-username-with-as-the-final-char-leads-to-an-error-loading-profile-page/173182/11 "2020-12-16T22:47:59Z")

</div>

Oh, so I’m afraid that is a Ruby bug:

```plaintext
➜ ruby --version           
ruby 3.0.0dev (2020-12-16T18:46:44Z master 93ba3ac036) [x86_64-linux]
➜ irb           
irb(main):001:0> "ΣΠΥΡΟΣ".downcase
=> "σπυροσ"

```

---

<div class="post-metadata">

### Author: ![chrispanag](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/chrispanag/32/105853_2.png) [@chrispanag](https://meta.discourse.org/u/chrispanag)
#### Post date: [16 december 2020 om 22:50 UTC](https://meta.discourse.org/t/unicode-username-with-as-the-final-char-leads-to-an-error-loading-profile-page/173182/12 "2020-12-16T22:50:03Z")

</div>

But it works nicely when the link is created… So there must be a way for it to work… (?)

[https://rembetiko.gr/u/σπυρος](https://rembetiko.gr/u/%CF%83%CF%80%CF%85%CF%81%CE%BF%CF%82)

---

<div class="post-metadata">

### Author: ![gerhard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gerhard/32/119479_2.png) [@gerhard](https://meta.discourse.org/u/gerhard)
#### Post date: [16 december 2020 om 22:51 UTC](https://meta.discourse.org/t/unicode-username-with-as-the-final-char-leads-to-an-error-loading-profile-page/173182/13 "2020-12-16T22:51:48Z")

</div>

It shouldn’t matter if Ruby converts the username into the grammatically correct lowercase version of the username as long as it always looks up users with the normalized username (`User.normalize_username` in Ruby) and the `username_lower` in the database.

Which JSON fetch fails? It’s quite likely that there’s a route that uses a different mechanism for comparing usernames.

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [16 december 2020 om 23:17 UTC](https://meta.discourse.org/t/unicode-username-with-as-the-final-char-leads-to-an-error-loading-profile-page/173182/14 "2020-12-16T23:17:57Z")

</div>

> [@gerhard](#):
>
> Which JSON fetch fails? It’s quite likely that there’s a route that uses a different mechanism for comparing usernames.

Maybe it’s because Ruby and JS have different implementations?

```ruby
➜ ruby --version           
ruby 3.0.0dev (2020-12-16T18:46:44Z master 93ba3ac036) [x86_64-linux]
➜ irb           
irb(main):001:0> "ΣΠΥΡΟΣ".downcase
=> "σπυροσ"

```

```js
➜ node
Welcome to Node.js v12.11.1.
Type ".help" for more information.
> "ΣΠΥΡΟΣ".toLowerCase()
'σπυρος'

```

Firefox does the same as NodeJS in my tests.

The endpoint `/u/#{username}.json` only bring the username column and not the `username_lower` column, so maybe we are relying in the browser here? Digging it now…

---

<div class="post-metadata">

### Author: ![gerhard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gerhard/32/119479_2.png) [@gerhard](https://meta.discourse.org/u/gerhard)
#### Post date: [16 december 2020 om 23:38 UTC](https://meta.discourse.org/t/unicode-username-with-as-the-final-char-leads-to-an-error-loading-profile-page/173182/15 "2020-12-16T23:38:45Z")

</div>

Oh, that’s bad. So, the problem is probably this:

> <https://github.com/discourse/discourse/blob/9870a0b6a1ba86e1e6192d32145507acbd53d43a/app/assets/javascripts/discourse/app/models/user.js#L264-L267>

I was going to suggest to add the `username_lower` to the `UserSerializer` on the server instead of doing it on the client, but this would still leave us with a couple of other occurrences of [username.toLowerCase](https://github.com/discourse/discourse/search?q=username.toLowerCase).

I wonder if the better solution would be to use `mini_racer` for calculating `username_lower` on the server when it contains non-ASCII characters. 🤔

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [16 december 2020 om 23:41 UTC](https://meta.discourse.org/t/unicode-username-with-as-the-final-char-leads-to-an-error-loading-profile-page/173182/16 "2020-12-16T23:41:26Z")

</div>

Well, independent of the workaround we chase I will report this to Ruby.

> **[Bug #17400: Incorrect character downcase for Greek Sigma - Ruby - Ruby Issue...](https://bugs.ruby-lang.org/issues/17400)**
>
> Redmine

---

<div class="post-metadata">

### Author: ![chrispanag](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/chrispanag/32/105853_2.png) [@chrispanag](https://meta.discourse.org/u/chrispanag)
#### Post date: [17 december 2020 om 00:10 UTC](https://meta.discourse.org/t/unicode-username-with-as-the-final-char-leads-to-an-error-loading-profile-page/173182/17 "2020-12-17T00:10:58Z")

</div>

Just for reference, PHP does it in the same way as Ruby… Makes me think that it is an intentional design (?)

You can test the code here:

> **[PHP Sandbox - Execute PHP code online through your browser](https://sandbox.onlinephp.io/code/8c64929f802e74c0c1ec4b50675f31faaa3a778d)**
>
> Run PHP code in your browser online with this tool in 400+ PHP versions

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [17 december 2020 om 02:13 UTC](https://meta.discourse.org/t/unicode-username-with-as-the-final-char-leads-to-an-error-loading-profile-page/173182/18 "2020-12-17T02:13:03Z")

</div>

Interestingly Postgres also fails here:

```plaintext
[2] pry(main)> DB.query_single('select lower(?)', 'ΣΠΥΡΟΣ')
=> ["σπυροσ"]

```

Perhaps we should simply special case this quirk in our internal Discourse method that handles calculating `username_lower` ?

Find all the methods that call `username_lower` pipe them to a central function and then have this special case allowed for (I guess we can use a mini\_racer call here if we wish or simply call `.lower` and fix it up afterwards with a `sub` call)

Updating the OP title here to make it clearer.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [17 december 2020 om 02:17 UTC](https://meta.discourse.org/t/unicode-username-with-as-the-final-char-leads-to-an-error-loading-profile-page/173182/19 "2020-12-17T02:17:49Z")

</div>

Given:

```plaintext
[4] pry(main)> "σπυρος".downcase
=> "σπυρος"

```

@chrispanag a trivial workaround for you is simply to change the username to `σπυρος`, username and username\_lower will be exactly the same and this will simply work.

I am mixed on adding workarounds to core just for this specific case, especially when a totally trivial workaround exists.

Additionally you could ban the use of Σ in usernames using our `allowed unicode username characters` setting which would ensure this issue never pops up.

All for fixing Ruby and Postgres here, but this is one long multi year battle to get these things fixed.

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [17 december 2020 om 02:46 UTC](https://meta.discourse.org/t/unicode-username-with-as-the-final-char-leads-to-an-error-loading-profile-page/173182/20 "2020-12-17T02:46:10Z")

</div>

> [@sam](#):
>
> All for fixing Ruby and Postgres here, but this is one long multi year battle to get these things fixed.

I fully agree here, we report the upstream bugs and Discourse users can use existing tools to workaround in the meanwhile.

[Next page](https://meta.discourse.org/t/unicode-username-with-as-the-final-char-leads-to-an-error-loading-profile-page/173182.md?page=2)
