Skip to content
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

Since 1.12.4 diff not working with blanks in filename or pathname #12768

Closed
3 of 7 tasks
fashberg opened this issue Sep 8, 2020 · 3 comments · Fixed by #12771
Closed
3 of 7 tasks

Since 1.12.4 diff not working with blanks in filename or pathname #12768

fashberg opened this issue Sep 8, 2020 · 3 comments · Fixed by #12771
Labels
Milestone

Comments

@fashberg
Copy link
Contributor

fashberg commented Sep 8, 2020

Description

Gitea Diff shows either wrong filenames or produces HTTP 500 if there is a blank in the filename/pathname of a changed file.

This bug applies only if git, but this seems to be default, does not quote the filenames at diff output.

Bug is since issue #12554 (#12575) - which became live in 1.12.4

Detail

Originally posted by @fashberg in #12554 (comment)

This fix breaks filenames with blanks in path (filename or foldername).

If you have
"diff --git a/folder/filename withBlank b/folder/filename withBlank"

you get now this wrong variable assignments:

a="a/folder/filename"
b="withBlank"

And the this two lines at https://github.com/go-gitea/gitea/blob/master/services/gitdiff/gitdiff.go#L592

	a = a[2:]
	b = b[2:]

are deleting the first two characters resulting in

a="folder/filename"
b="thBlank"

In the diff you see a renaming filename → thBlank and if you click on the link to 'Show File' it links to 'thBlank' which results in 404.

The bug is getting worse if the filename has only a single character after the first blank, e.g. test - file

Resulting in

a="a/folder/test"
b="-"

Because strlen of b is only 2 the substring(b, 2)/ (b = b[2:]) will not work because string is too short, resulting in Error 500

2020/09/08 15:43:06 ...les/context/panic.go:35:1() [E] PANIC:: runtime error: slice bounds out of range [2:1]
	/usr/lib/go-1.13/src/runtime/panic.go:103 (0x436882)
		goPanicSliceB: panic(boundsError{x: int64(x), signed: true, y: y, code: boundsSliceB})
	/home/fashberg/gitea/services/gitdiff/gitdiff.go:593 (0x1d4191a)

So the middle = strings.Index(line, " b/") hack was not so bad.

Now filenames with blanks are completely broken in 1.12.4 and master!

Why ignoring the lines with --- a/xxxx and +++ b/xxxx?
There you can cat the real filename without any quoting problems. OK, new files are having --- /dev/null and maybe there are some more special cases.

Kind Regards
Folke

@zeripath
Copy link
Contributor

zeripath commented Sep 8, 2020

Looks like there can be no way of actually detemining which file has been changed from the diff line:

diff --git a/a b/file b/a a/file b/a b/file b/a a/file
index d2186f1..f5c8ed2 100644
--- a/a b/file b/a a/file	
+++ b/a b/file b/a a/file	
@@ -1,3 +1,2 @@
 Create a weird file.
 
-and what does diff do here?
\ No newline at end of file

@mrsdizzie
Copy link
Member

Could we somehow refactor and use output git diff --name-only or git diff --name-status for this instead of looking at the diff itself?

zeripath added a commit to zeripath/gitea that referenced this issue Sep 8, 2020
Following further testing it has become apparent that the diff line
cannot be used to determine filenames for diffs with any sort of predictability
the answer therefore is to use the other lines that are provided with a diff

Fix go-gitea#12768

Signed-off-by: Andrew Thornton <art27@cantab.net>
@lunny lunny added the type/bug label Sep 9, 2020
@lunny lunny added this to the 1.12.5 milestone Sep 9, 2020
zeripath added a commit that referenced this issue Sep 9, 2020
Following further testing it has become apparent that the diff line
cannot be used to determine filenames for diffs with any sort of predictability
the answer therefore is to use the other lines that are provided with a diff

Fix #12768

Signed-off-by: Andrew Thornton <art27@cantab.net>
@zeripath
Copy link
Contributor

zeripath commented Sep 9, 2020

Hopefully this won't reveal (yet) another bug

zeripath added a commit to zeripath/gitea that referenced this issue Sep 9, 2020
Backport go-gitea#12771

Following further testing it has become apparent that the diff line
cannot be used to determine filenames for diffs with any sort of predictability
the answer therefore is to use the other lines that are provided with a diff

Fix go-gitea#12768

Signed-off-by: Andrew Thornton <art27@cantab.net>
zeripath added a commit that referenced this issue Sep 9, 2020
Backport #12771

Following further testing it has become apparent that the diff line
cannot be used to determine filenames for diffs with any sort of predictability
the answer therefore is to use the other lines that are provided with a diff

Fix #12768

Signed-off-by: Andrew Thornton <art27@cantab.net>
@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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants