-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Prevent NPE in CSV diff rendering when column removed #17018
Prevent NPE in CSV diff rendering when column removed #17018
Conversation
I see integration isn't passing, and I also found this case causes and index out of bounds error. Will fix. BASE:
HEAD:
|
@silverwind @zeripath Ok, if you could play with this reworking of all things CSV Diff locally (try to break with all sorts of CSV diffs) and review, appreciate it! |
This comment has been minimized.
This comment has been minimized.
66e8960
to
9f70afe
Compare
Ok, fixed initial commit with EOF 500 error. |
Just a note, still working on this, have made great progress in making sure it is done right. Even adding in it noting when a column has been moved so that is brought to the attention of the person reviewing the PR. |
Finally got a chance to work on this after dealing with COVID and lots of other work. Hope this gets looked at. Please feel free to ask question but hopefully the comments make sense. Takes a bit of work to nicely show a CSV diff. As already stated, now also shows moved columns but accounts for column additions and deletions (that is, if columns before a column were added or deleted, it doesn't flag the existing column as moved). Example diff: So in the above, phone and email got moved to the end, other columns added and deleted. You can see this CSV on try.gitea.io but of course the diff throws a 500 error there, hence this fix: Orig: https://try.gitea.io/richmahntest/test/src/commit/4d2ec906dafbb5082ed1aa0a3f50107139c42711/names.csv |
make lgtm work |
Please send backport |
Making backport! |
…lumn removed Fixes go-gitea#16837 if a column is deleted.
* SECURITY * Upgrade Bluemonday to v1.0.16 (go-gitea#17372) (go-gitea#17374) * Ensure correct SSH permissions check for private and restricted users (go-gitea#17370) (go-gitea#17373) * BUGFIXES * Prevent NPE in CSV diff rendering when column removed (go-gitea#17018) (go-gitea#17377) * Offer rsa-sha2-512 and rsa-sha2-256 algorithms in internal SSH (go-gitea#17281) (go-gitea#17376) * Don't panic if we fail to parse U2FRegistration data (go-gitea#17304) (go-gitea#17371) * Ensure popup text is aligned left (backport for 1.15) (go-gitea#17343) * Ensure that git daemon export ok is created for mirrors (go-gitea#17243) (go-gitea#17306) * Disable core.protectNTFS (go-gitea#17300) (go-gitea#17302) * Use pointer for wrappedConn methods (go-gitea#17295) (go-gitea#17296) * AutoRegistration is supposed to be working with disabled registration (backport) (go-gitea#17292) * Handle duplicate keys on GPG key ring (go-gitea#17242) (go-gitea#17284) * Fix SVG side by side comparison link (go-gitea#17375) (go-gitea#17391) Signed-off-by: Andrew Thornton <[email protected]>
* SECURITY * Upgrade Bluemonday to v1.0.16 (#17372) (#17374) * Ensure correct SSH permissions check for private and restricted users (#17370) (#17373) * BUGFIXES * Prevent NPE in CSV diff rendering when column removed (#17018) (#17377) * Offer rsa-sha2-512 and rsa-sha2-256 algorithms in internal SSH (#17281) (#17376) * Don't panic if we fail to parse U2FRegistration data (#17304) (#17371) * Ensure popup text is aligned left (backport for 1.15) (#17343) * Ensure that git daemon export ok is created for mirrors (#17243) (#17306) * Disable core.protectNTFS (#17300) (#17302) * Use pointer for wrappedConn methods (#17295) (#17296) * AutoRegistration is supposed to be working with disabled registration (backport) (#17292) * Handle duplicate keys on GPG key ring (#17242) (#17284) * Fix SVG side by side comparison link (#17375) (#17391) Signed-off-by: Andrew Thornton <[email protected]>
Frontport go-gitea#17392 * SECURITY * Upgrade Bluemonday to v1.0.16 (go-gitea#17372) (go-gitea#17374) * Ensure correct SSH permissions check for private and restricted users (go-gitea#17370) (go-gitea#17373) * BUGFIXES * Prevent NPE in CSV diff rendering when column removed (go-gitea#17018) (go-gitea#17377) * Offer rsa-sha2-512 and rsa-sha2-256 algorithms in internal SSH (go-gitea#17281) (go-gitea#17376) * Don't panic if we fail to parse U2FRegistration data (go-gitea#17304) (go-gitea#17371) * Ensure popup text is aligned left (backport for 1.15) (go-gitea#17343) * Ensure that git daemon export ok is created for mirrors (go-gitea#17243) (go-gitea#17306) * Disable core.protectNTFS (go-gitea#17300) (go-gitea#17302) * Use pointer for wrappedConn methods (go-gitea#17295) (go-gitea#17296) * AutoRegistration is supposed to be working with disabled registration (backport) (go-gitea#17292) * Handle duplicate keys on GPG key ring (go-gitea#17242) (go-gitea#17284) * Fix SVG side by side comparison link (go-gitea#17375) (go-gitea#17391) Signed-off-by: Andrew Thornton <[email protected]>
Fixes go-gitea#16837 if a column is deleted. We were clobbering the columns that were added by looping through the aline (base) and then when bline (head) was looped through, it clobbered what was in the "cells" array that is show in the diff, and then left a nil cell because nothing was shifted. This fix properly shifts the cells, and properly puts the b cell either at its location or after, according to what the aline placed in the cells. This includes test, adding a new test function since adding/removing cells works best with three columns, not two, which results in 4 columns of the resulting cells because it has a deleted column and an added column. If you try this locally, you can try those cases and others, such as adding a column. There was no need to do anything special for the rows when `aline == 0 || bline == 0` so that was removed. This allows the same code to be used for removed or added lines, with the bcell text always being the RightCell, acell text being the LeftCell. I still added the patch zeripath gave at go-gitea#16837 (comment) so that just in case for some reason a cell is nil (which shouldn't happen now) it doesn't throw a 500 error, so the user can at least view the raw diff. Also fixes in the [view.go](https://github.com/go-gitea/gitea/pull/17018/files#diff-43a7f4747c7ba8bff888c9be11affaafd595fd55d27f3333840eb19df9fad393L521) file how if a CSV file is empty (either created empty or if you edit it and remove all contents) it throws a huge 500 error when you then save it (when you view the file). Since we allow creating, saving and pushing empty files, we shouldn't throw an error on an empty CSV file, but just show its empty contents. This doesn't happen if it is a Markdown file or other type of file that is empty. EDIT: Now handled in the markup/csv renderer code
Fixes #16837 if a column is deleted.
We were clobbering the columns that were added by looping through the aline (base) and then when bline (head) was looped through, it clobbered what was in the "cells" array that is show in the diff, and then left a nil cell because nothing was shifted.
This fix properly shifts the cells, and properly puts the b cell either at its location or after, according to what the aline placed in the cells.
This includes test, adding a new test function since adding/removing cells works best with three columns, not two, which results in 4 columns of the resulting cells because it has a deleted column and an added column. If you try this locally, you can try those cases and others, such as adding a column.
There was no need to do anything special for the rows when
aline == 0 || bline == 0
so that was removed. This allows the same code to be used for removed or added lines, with the bcell text always being the RightCell, acell text being the LeftCell.I still added the patch @zeripath gave at #16837 (comment) so that just in case for some reason a cell is nil (which shouldn't happen now) it doesn't throw a 500 error, so the user can at least view the raw diff.
Also fixes in the view.go file how if a CSV file is empty (either created empty or if you edit it and remove all contents) it throws a huge 500 error when you then save it (when you view the file). Since we allow creating, saving and pushing empty files, we shouldn't throw an error on an empty CSV file, but just show its empty contents. This doesn't happen if it is a Markdown file or other type of file that is empty.
EDIT: Now handled in the markup/csv renderer code