Skip to content

4 byte unicode returns a 500 w/mysql #3513

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
2 of 7 tasks
philfry opened this issue Feb 14, 2018 · 2 comments
Closed
2 of 7 tasks

4 byte unicode returns a 500 w/mysql #3513

philfry opened this issue Feb 14, 2018 · 2 comments
Labels
type/enhancement An improvement of existing functionality
Milestone

Comments

@philfry
Copy link
Contributor

philfry commented Feb 14, 2018

  • Gitea version (or commit ref): 1.4.0rc1
  • Git version: 2.16.1
  • Operating system: CentOS 7
  • Database (use [x]):
    • PostgreSQL
    • MySQL
    • MSSQL
    • SQLite
  • Can you reproduce the bug at https://try.gitea.io:
    • Yes (provide example URL)
    • No
    • Not relevant
  • Log gist:

Description

when using 4 byte unicode, like emojis, in an issue (subject, content, ..) gitea will return a 500. This is because the database was created as utf8 by gitea and gitea is using the utf8 namespace when connecting to it.
This issue can be solved by

  1. altering all tables/columns from utf8 to utf8mb4
# quick'n dirty, we don't need alter tables here
mysqldump gitea | sed 's/\butf8\b/utf8mb4/g' > gitea_utf8mb4.sql
mysql gitea < gitea_utf8mb4.sql

and

  1. patching gitea to use utf8mb4 when connecting to the db:
diff --git i/models/models.go w/models/models.go
index 7738e1a3..9693b88c 100644
--- i/models/models.go
+++ w/models/models.go
@@ -205,10 +205,10 @@ func getEngine() (*xorm.Engine, error) {
        switch DbCfg.Type {
        case "mysql":
                if DbCfg.Host[0] == '/' { // looks like a unix socket
-                       connStr = fmt.Sprintf("%s:%s@unix(%s)/%s%scharset=utf8&parseTime=true",
+                       connStr = fmt.Sprintf("%s:%s@unix(%s)/%s%scharset=utf8mb4&parseTime=true",
                                DbCfg.User, DbCfg.Passwd, DbCfg.Host, DbCfg.Name, Param)
                } else {
-                       connStr = fmt.Sprintf("%s:%s@tcp(%s)/%s%scharset=utf8&parseTime=true",
+                       connStr = fmt.Sprintf("%s:%s@tcp(%s)/%s%scharset=utf8mb4&parseTime=true",
                                DbCfg.User, DbCfg.Passwd, DbCfg.Host, DbCfg.Name, Param)
                }
        case "postgres":

Unfortunately, I'm not familiar enough with the gitea source code regarding the database creation (I'm pretty sure it's somewhat related to the types/struct in models/*.go, though), so sorry for not providing a patch.

@philfry
Copy link
Contributor Author

philfry commented Feb 14, 2018

related to #2711

@lunny lunny added this to the 1.5.0 milestone Feb 16, 2018
@lunny lunny added the type/enhancement An improvement of existing functionality label Feb 16, 2018
@philfry
Copy link
Contributor Author

philfry commented May 23, 2018

see #3516

@philfry philfry closed this as completed May 23, 2018
@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type/enhancement An improvement of existing functionality
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants