mirror of
https://github.com/go-gitea/gitea.git
synced 2026-07-15 20:09:18 -05:00
Commenting on a diff of a file with spaces separating short tokens makes the PR page inaccessible #6931
Closed
opened 2025-11-02 07:11:23 -06:00 by GiteaMirror
·
23 comments
No Branch/Tag Specified
main
release/v1.25
release/v1.24
release/v1.23
release/v1.22
release/v1.21
release/v1.20
release/v1.19
release/v1.18
release/v1.17
release/v1.16
release/v1.15
release/v1.14
release/v1.13
release/v1.12
release/v1.11
release/v1.10
release/v1.9
release/v1.8
v1.25.3
v1.25.2
v1.25.1
v1.25.0
v1.24.7
v1.25.0-rc0
v1.26.0-dev
v1.24.6
v1.24.5
v1.24.4
v1.24.3
v1.24.2
v1.24.1
v1.24.0
v1.23.8
v1.24.0-rc0
v1.25.0-dev
v1.23.7
v1.23.6
v1.23.5
v1.23.4
v1.23.3
v1.23.2
v1.23.1
v1.23.0
v1.23.0-rc0
v1.24.0-dev
v1.22.6
v1.22.5
v1.22.4
v1.22.3
v1.22.2
v1.22.1
v1.22.0
v1.23.0-dev
v1.22.0-rc1
v1.21.11
v1.22.0-rc0
v1.21.10
v1.21.9
v1.21.8
v1.21.7
v1.21.6
v1.21.5
v1.21.4
v1.21.3
v1.21.2
v1.20.6
v1.21.1
v1.21.0
v1.21.0-rc2
v1.21.0-rc1
v1.20.5
v1.22.0-dev
v1.21.0-rc0
v1.20.4
v1.20.3
v1.20.2
v1.20.1
v1.20.0
v1.19.4
v1.21.0-dev
v1.20.0-rc2
v1.20.0-rc1
v1.20.0-rc0
v1.19.3
v1.19.2
v1.19.1
v1.19.0
v1.19.0-rc1
v1.20.0-dev
v1.19.0-rc0
v1.18.5
v1.18.4
v1.18.3
v1.18.2
v1.18.1
v1.18.0
v1.17.4
v1.18.0-rc1
v1.19.0-dev
v1.18.0-rc0
v1.17.3
v1.17.2
v1.17.1
v1.17.0
v1.17.0-rc2
v1.16.9
v1.17.0-rc1
v1.18.0-dev
v1.16.8
v1.16.7
v1.16.6
v1.16.5
v1.16.4
v1.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c2
v1.3.3
v1.4.0-rc1
v1.3.2
v1.3.1
v1.3.0
v1.3.0-rc2
v1.3.0-rc1
v1.2.3
v1.2.2
v1.2.1
v1.2.0
v1.2.0-rc3
v1.2.0-rc2
v1.1.4
v1.2.0-rc1
v1.1.3
v1.1.2
v1.1.1
v1.1.0
v1.0.2
v1.0.1
v1.0.0
v0.9.99
Labels
Clear labels
$20
$250
$50
$500
backport/done
💎 Bounty
docs-update-needed
good first issue
hacktoberfest
issue/bounty
issue/confirmed
issue/critical
issue/duplicate
issue/needs-feedback
issue/not-a-bug
issue/regression
issue/stale
issue/workaround
lgtm/need 2
modifies/api
modifies/translation
outdated/backport/v1.18
outdated/theme/markdown
outdated/theme/timetracker
performance/bigrepo
performance/cpu
performance/memory
performance/speed
pr/breaking
proposal/accepted
proposal/rejected
pr/wip
pull-request
reviewed/wontfix
💰 Rewarded
skip-changelog
status/blocked
topic/accessibility
topic/api
topic/authentication
topic/build
topic/code-linting
topic/commit-signing
topic/content-rendering
topic/deployment
topic/distribution
topic/federation
topic/gitea-actions
topic/issues
topic/lfs
topic/mobile
topic/moderation
topic/packages
topic/pr
topic/projects
topic/repo
topic/repo-migration
topic/security
topic/theme
topic/ui
topic/ui-interaction
topic/ux
topic/webhooks
topic/wiki
type/bug
type/deprecation
type/docs
type/enhancement
type/feature
type/miscellaneous
type/proposal
type/question
type/refactoring
type/summary
type/testing
type/upstream
Mirrored from GitHub Pull Request
No Label
Milestone
No items
No Milestone
Projects
Clear projects
No project
No Assignees
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: github-starred/gitea#6931
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @abread on GitHub (Feb 26, 2021).
Rendering the PR page errors with
template: repo/issue/view_content/comments:470:20: executing "repo/issue/view_content/comments" at <CommentMustAsDiff (index $comms 0)>: error calling CommentMustAsDiff: runtime error: slice bounds out of range [2:1]I was unable to get a proper stacktrace (or logs), but I manually traced the offending slice indexing to this line.
The git-diff output filename extractor (
readFileName) cannot properly split the old name from the new name (and panics because instead of findingb/<filename>to removeb/it finds the single letter bit of the old filename).git-diff outputs unquoted paths because Gitea sets
core.quotePath(git config) tofalse. Interestingly,readFileNamehas code handling quoted paths already. It did work too when I changed the offending patch in the comments table to have quoted paths.Steps to reproduce:
sdafdsaf z1 - the first document.txt(anything in the format<any amount of characters that are not a space> <1 non-space character>[ <anything>]works as far as I can tell)Fix suggestion
Maybe there's a really good reason to keep it, but imho leaving all paths returned by git quoted (
core.quotePath=true) is the best option for sane path handling everywhere.It may already be ok to do so: setting it to true didn't break any tests on my machine at least.
[x]):@zeripath commented on GitHub (Feb 26, 2021):
I've said it before and I'll say it again I hate our diff infrastructure.
@zeripath commented on GitHub (Feb 26, 2021):
OK so this is not rendering the diff pages themselves but rather a problem with rendering a comment on the pull itself right?
@abread commented on GitHub (Feb 26, 2021):
I think so yes (at least that's what I gather from the error message)
@zeripath commented on GitHub (Feb 26, 2021):
yup - https://try.gitea.io/templatepanic/templatepanic/pulls/3/files this doesn't panic.
@zeripath commented on GitHub (Feb 26, 2021):
OK so this is not a failure with the code I spent so effing long on making work for rendering of diffs in the first place.
@zeripath commented on GitHub (Feb 26, 2021):
No doubt the problem will be similar - in the end the reality is that there is no way to reliably split up: diff a/filename b/filename2 without forcing it to be always quoted.
@zeripath commented on GitHub (Feb 27, 2021):
Just to highlight this issue here is a particularly catastrophic example:
from the
diff --gitlines alone what are the new and old filenames...@zeripath commented on GitHub (Feb 27, 2021):
oh yeah and this particular doozy:
@abread commented on GitHub (Feb 27, 2021):
Yesterday I bit the bullet and looked through all the code calling git (started by looking for everything using
os/execand went up from there). I found only43 places that are not ready to handle quoted paths (1 looks like dead code).I think I can get a PR fixing this (and potentially other issues with paths) that flips
core.quotedPathtotruedone today@zeripath commented on GitHub (Feb 27, 2021):
No don't worry I'm there already
@zeripath commented on GitHub (Feb 27, 2021):
Just thinking about fixing the comment as patch code to make it quote or not but I guess that needs to be done as a different PR.
@zeripath commented on GitHub (Feb 27, 2021):
Hmm. I think I'm gonna merge the fix into #14804
@abread commented on GitHub (Feb 27, 2021):
I think it's easier to just assume paths are quoted in
ParsePatchand change the ~3 callers to callgit -c core.quotedpath=true ...no?@zeripath commented on GitHub (Feb 27, 2021):
ah you've made the mistake of assuming that these particular "diffs" came from git - they're from some code that hacks them out of git diffs.
The reality is that these diffs are stored in plaintext in your db so we still need to be able to parse them.
In any case core.quotedpath doesn't guarantee what you think it does. The answer for forcing every git from 1.7.2+ to quote its paths is to pass
git diff --src-prefix=\\a/ --dst-prefix=\\b/and then trim off the\\.Honestly it's just crazy.
@abread commented on GitHub (Feb 27, 2021):
Ah right I was forgetting those
At one point I had the idea of
gitea doctoring them into sane quotedness, but now that I think about it the only reason they're in the DB is becausegit gccould throw away the originals right?On February 27, 2021 1:30:42 PM UTC, zeripath notifications@github.com wrote:
@skillcoder commented on GitHub (Mar 18, 2021):
I'm updatated gitea 1.13.2 -> 1.13.4
But I still have see broken PR
It's normal ?
@miili commented on GitHub (Mar 18, 2021):
Same here. Is there any way to fix this?
Can we fix the bad PR or throw it away?
@zeripath commented on GitHub (Mar 18, 2021):
Please open a new issue instead of commenting on old issues and replicate the issue on try.gitea.io, and give us some logs.
Please refer to this issue on the new issue so we can go from there.
@zeripath commented on GitHub (Mar 18, 2021):
@miili without even giving us an example of what is breaking how can you expect there to be a fix? The provided testcase referred to in the in this issue is fixed and frankly it's extremely unhelpful of you to write things like: "Can we fix the bad PR or throw it away."
@miili commented on GitHub (Mar 19, 2021):
@zeripath, thank you for you respone. The exact issue and how to replicate it has been described in great detail in this issue. I don't feel the need to document or replicate it again.
The bad PR is refering to the broken Pull Request on the production system, which cannot be accessed anymore.
Here is a link, if that helps https://git.pyrocko.org/pyrocko/pyrocko/pulls/159#issuecomment-785
Can the broken PR be fixed?
@zeripath commented on GitHub (Mar 24, 2021):
@miili could you update to 1.13.6 please we should get more information then
@zeripath commented on GitHub (Mar 24, 2021):
Also looking at:
https://git.pyrocko.org/pyrocko/pyrocko/pulls/159/files
I can't see an obvious thing that would cause the problem but I wonder
if you'd be able to help me out to figure out what the problem is or
could be.
Part of the problem is that the panic is occurring inside the template
executer so we're lacking more information as to exactly where the
panic is occuring. It would be possible to add a recover handler into
the function to help get information into why the result is failing
but I can't seem to replicate this locally at all.
If you would be able to give me a copy of your issue, pull_request and
comment tables as relating to this request I might be able to figure
it out.
1.13.6 has changed the code to give us more information about the panic but it would still be helpful to figure things out
@zeripath commented on GitHub (Mar 29, 2021):
@miili @skillcoder Are either of you associated with pyrocko? If so the upgrade to 1.13.6 has revealed the source of the problem.
As I suspected it was not associated to this PR.