go-gitea / gitea

Git with a cup of tea! Painless self-hosted all-in-one software development service, including Git hosting, code review, team collaboration, package registry and CI/CD
https://gitea.com
MIT License
44.61k stars 5.45k forks source link

Login with Safari: Error updating user language #14793

Closed louis77 closed 3 years ago

louis77 commented 3 years ago

This is a follow-up to issue #9806 which is closed and unfortunately not available for reopening.

Logging in with Safari Version 14.0.3 (16610.4.3.1.4) causes the following error message:

routers/user/auth.go:524:[handleSignInFull()] Error updating user language [user: 3, locale: de-DE-u-rg-chzzzz]

and shows an empty page. Obviously Safari is sending a strange locale.

Checking with whatismyip.org:

HTTP_HOST: www.whatsmyip.org
HTTP_ACCEPT: text/html, application/xhtml+xml, application/xml;q=0.9, */*;q=0.8
HTTP_ACCEPT_LANGUAGE: de-ch
HTTP_CONNECTION: keep-alive
HTTP_ACCEPT_ENCODING: gzip, deflate, br
HTTP_USER_AGENT: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0.3 Safari/605.1.15

Gitea version: 1.13.2 built with GNU Make 4.2.1, go1.14.6 : bindata Running gitea binary compiled from source with no reverse proxies on port 443 OS: Linux 4.19.0-13-cloud-amd64 #1 SMP Debian 4.19.160-2 (2020-11-28) x86_64 GNU/Linux DB: PostgreSQL 12

I've changed the language column in the user table:

ALTER TABLE "public"."user" ALTER COLUMN "language" SET DATA TYPE varchar(20);

then the error goes away. So either the locale must be stripped or the column length must be made greater than 5.

lunny commented 3 years ago

So strip de-DE-u-rg-chzzzz to de-DE is acceptable?

louis77 commented 3 years ago

I found this issue in the golang repo: https://github.com/golang/go/issues/24211

Seems to be a bug in a Go lib. The most recent "solution" for this is:

langTag, _, _ := languageMatcher.Match(tags...)
langTagString := langTag.String()[0:2]
zeripath commented 3 years ago

So strip de-DE-u-rg-chzzzz to de-DE is acceptable?

What we should do is strip off the - one by one until there is a locale available that matches

lunny commented 3 years ago

@louis77 could you help to confirm #15452 fix this?

louis77 commented 3 years ago

I can confirm, works well for me now.