Skip to content

gitea database dump doesn't escape LF character #6907

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
3 tasks done
samangh opened this issue May 11, 2019 · 6 comments
Closed
3 tasks done

gitea database dump doesn't escape LF character #6907

samangh opened this issue May 11, 2019 · 6 comments
Labels
issue/confirmed Issue has been reviewed and confirmed to be present or accepted to be implemented type/bug

Comments

@samangh
Copy link

samangh commented May 11, 2019

  • Gitea version (or commit ref): 1.8.0
  • Git version: 2.21.0
  • Operating system: Linux (Debian Buster)
  • Database (use [x]):
    • MySQL
    • SQLite
  • Can you reproduce the bug at https://try.gitea.io:
    • Not relevant
  • Log gist:

When exporting via gitea dump,the \n at then end of commit message title (in column content of table action) is not properly escaped.

I've checked that this happens when exporting both from MySQL and NoSQL databases. As an example,

$ ./gitea dump
$ unzip -j gitea-dump-1557579865.zip gitea-db.sql `pwd`/gitea-db.sql
$ grep "66fd8c3d224c1f358f57d242374563ad55543761" gitea-db.sql

INSERT INTO `action` (`id`, `user_id`, `op_type`, `act_user_id`, `repo_id`, `comment_id`, `is_deleted`, `ref_name`, `is_private`, `content`, `created_unix`) VALUES (894, 1, 5, 1, 1, 0, false, 'master', true, '{"Len":1,"Commits":[{"Sha1":"66fd8c3d224c1f358f57d242374563ad55543761","Message":"test \\n \\r \\t\n","AuthorEmail":"[email protected]","AuthorName":"Saman Ghannadzadeh","CommitterEmail":"[email protected]","CommitterName":"Saman Ghannadzadeh","Timestamp":"2019-05-11T13:31:40+01:00"}],"CompareURL":"saman/dotfiles/compare/5f81ccf3c05313658d4a9edd817526046e6a8cef...66fd8c3d224c1f358f57d242374563ad55543761"}', 1557577915);

Notice the Message":"test \\n \\r \\t\n". The special characters are escpaed, except the last \n.

This can cause mashalling errors when the dump is later imported into a database, see #6793.

@samangh samangh changed the title gitea database dump doesn't escape some special characters gitea database dump doesn't escape LF character May 11, 2019
@lunny lunny added the type/bug label May 12, 2019
@stale
Copy link

stale bot commented Jul 11, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs during the next 2 weeks. Thank you for your contributions.

@stale stale bot added the issue/stale label Jul 11, 2019
@lunny lunny added the issue/confirmed Issue has been reviewed and confirmed to be present or accepted to be implemented label Jul 11, 2019
@stale stale bot removed the issue/stale label Jul 11, 2019
@PerfectSlayer
Copy link

PerfectSlayer commented Aug 23, 2019

Hello,

I encounter the same issue with 1.8.2 version after dumping (gitea dump) and re-importing data (mysql -uUSER -pPASSWD DATABASE < gitea-db.sql).

I think I will try to write a script to patch my backup to convert \n to \\n in Commits[].Message from content field for op_type = 5||16 in action database. Any device before implementing this?

Thanks!

@nodiscc
Copy link
Contributor

nodiscc commented Feb 10, 2020

I also encounter this problem when trying to restore a backup from Gitea 1.8.0 on a recent release. This workaround worked for me:

sed -i 's/\\n/\\\\n/g' gitea-dump-1581252886/gitea-db.sql
sed -i 's/\\r/\\\\e/g' gitea-dump-1581252886/gitea-db.sql

However considering the numerous issues I noted at #9100 (comment) you may want to remove the dump command altogether from gitea, and simply provide backup instructions (dump the database using standard tools, backup the dump and data directory)

@hefengxian
Copy link

For temp solution, we can use database dump tool, for example on MySQL

mysqldump -h192.168.1.xxx -uxxx -pxxx -P3306 --single-transaction --set-gtid-purged=OFF --column-statistics=0 --default-character-set=utf8mb4 --databases gitea > gitea.sql

then import to MySQL

mysql --default-character-set=utf8mb4 -uxxx -pxxx gitea < gitea.sql

@zeripath
Copy link
Contributor

It would be helpful to report which versions of Gitea have this problem and if they are fixed on the newer versions. (including 1.14 - where it should be fixed)

@go-gitea go-gitea locked and limited conversation to collaborators May 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
issue/confirmed Issue has been reviewed and confirmed to be present or accepted to be implemented type/bug
Projects
None yet
Development

No branches or pull requests

7 participants