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

Commit search breaks when looking for opening square bracket "[" #28269

Closed
pcamilo89 opened this issue Nov 28, 2023 · 3 comments · Fixed by #28744
Closed

Commit search breaks when looking for opening square bracket "[" #28269

pcamilo89 opened this issue Nov 28, 2023 · 3 comments · Fixed by #28744
Labels
issue/confirmed Issue has been reviewed and confirmed to be present or accepted to be implemented type/bug

Comments

@pcamilo89
Copy link

Description

When trying to filter commits on a repo where the commit message have the type of commit enclosed in square brackets, e.g. "[build] Update libraries to next mayor version", the search doesn't behave as expected.
The different cases I tried were:

  • When you search for a tag enclosed in square brackets, e.g. "[build]", it shows a bunch of results that doesn't match the search.
  • when you search for a tag but missing the starting square bracket, e.g. "build]", the search gives the correct results.
  • when you search for a tag enclosed in square brackets and escape the opening bracket, e.g. "\[build]", the search gives the correct results.
  • when you search only for an opening square bracket, e.g. "[", it shows an error page.
  • when you search only for an opening square bracket and escape it, e.g. "\[", it shows all the commits that have an opening square bracket which is the correct result.

Gitea Version

1.21.0

Can you reproduce the bug on the Gitea demo site?

Yes

Log Gist

No response

Screenshots

When you search for "[" shows this error page
image

Git Version

2.40.1, Wire Protocol Version 2 Enabled

Operating System

Debian GNU/Linux 11

How are you running Gitea?

gitea/gitea:1.21.0 Docker image

Database

None

@lng2020 lng2020 added the issue/confirmed Issue has been reviewed and confirmed to be present or accepted to be implemented label Nov 29, 2023
@lng2020
Copy link
Member

lng2020 commented Nov 29, 2023

FYI, keywords are used here which lacked some checks.

for _, v := range opts.Keywords {
cmd.AddOptionFormat("--grep=%s", v)
}

@me-heer
Copy link
Contributor

me-heer commented Dec 30, 2023

Hi, can I work on this?

@me-heer
Copy link
Contributor

me-heer commented Dec 30, 2023

The default behavior of --grep in git log is to interpret the keyword as a regular expression.

If we want our keywords to be interpreted as 'strings', we should use -F flag.

I'm not sure if using regular expressions was the intended behavior previously.

lunny pushed a commit that referenced this issue Jan 10, 2024
Fixes #28269

The [default
behavior](https://git-scm.com/docs/git-log#Documentation/git-log.txt---basic-regexp)
of --grep in git log is to interpret the keyword as a regular
expression. This causes the search to fail in the cases where the search
keyword contains a `[`, since `[` is a special character used in grep.

If we want our keywords to be interpreted as 'strings', we should use
[-F
flag](https://git-scm.com/docs/git-log#Documentation/git-log.txt---basic-regexp).
GiteaBot pushed a commit to GiteaBot/gitea that referenced this issue Jan 10, 2024
Fixes go-gitea#28269

The [default
behavior](https://git-scm.com/docs/git-log#Documentation/git-log.txt---basic-regexp)
of --grep in git log is to interpret the keyword as a regular
expression. This causes the search to fail in the cases where the search
keyword contains a `[`, since `[` is a special character used in grep.

If we want our keywords to be interpreted as 'strings', we should use
[-F
flag](https://git-scm.com/docs/git-log#Documentation/git-log.txt---basic-regexp).
KN4CK3R pushed a commit that referenced this issue Jan 10, 2024
Backport #28744 by @me-heer

Fixes #28269

The [default
behavior](https://git-scm.com/docs/git-log#Documentation/git-log.txt---basic-regexp)
of --grep in git log is to interpret the keyword as a regular
expression. This causes the search to fail in the cases where the search
keyword contains a `[`, since `[` is a special character used in grep.

If we want our keywords to be interpreted as 'strings', we should use
[-F
flag](https://git-scm.com/docs/git-log#Documentation/git-log.txt---basic-regexp).

Co-authored-by: Mihir Joshi <mihir67mj@gmail.com>
fuxiaohei pushed a commit to fuxiaohei/gitea that referenced this issue Jan 17, 2024
Fixes go-gitea#28269

The [default
behavior](https://git-scm.com/docs/git-log#Documentation/git-log.txt---basic-regexp)
of --grep in git log is to interpret the keyword as a regular
expression. This causes the search to fail in the cases where the search
keyword contains a `[`, since `[` is a special character used in grep.

If we want our keywords to be interpreted as 'strings', we should use
[-F
flag](https://git-scm.com/docs/git-log#Documentation/git-log.txt---basic-regexp).
silverwind pushed a commit to silverwind/gitea that referenced this issue Feb 20, 2024
Fixes go-gitea#28269

The [default
behavior](https://git-scm.com/docs/git-log#Documentation/git-log.txt---basic-regexp)
of --grep in git log is to interpret the keyword as a regular
expression. This causes the search to fail in the cases where the search
keyword contains a `[`, since `[` is a special character used in grep.

If we want our keywords to be interpreted as 'strings', we should use
[-F
flag](https://git-scm.com/docs/git-log#Documentation/git-log.txt---basic-regexp).
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 25, 2024
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

Successfully merging a pull request may close this issue.

3 participants