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

Regular expression for go-test compilation pattern is too broad #361

Open
phst opened this issue May 10, 2020 · 0 comments · May be fixed by #363
Open

Regular expression for go-test compilation pattern is too broad #361

phst opened this issue May 10, 2020 · 0 comments · May be fixed by #363

Comments

@phst
Copy link
Contributor

phst commented May 10, 2020

The regular expression to find Go test errors is currently (

'(go-test . ("^\\s-+\\([^()\t\n]+\\):\\([0-9]+\\):? .*$" 1 2)) t)))
) "^\\s-+\\([^()\t\n]+\\):\\([0-9]+\\):? .*$". The problem is that this regex is very broad and matches too much:

  1. The \s-+ also matches newlines (at least when using the standard syntax table).
  2. The [^()\t\n]+ group matches a ton of things: spaces, exotic characters, NUL bytes, ...

Combined, these two mean that e.g. a GNU-style file:line:column: message line that follows a newline is matched incorrectly:

(with-syntax-table (standard-syntax-table)
  (let ((regex "^\\s-+\\([^()\t\n]+\\):\\([0-9]+\\):? .*$")
        (line "\nfile.go:1:2: word word"))
    (list
     (string-match regex line)
     (match-string 1 line))))

⇒ (0 "file.go:1")

Here, this incorrectly treats file.go:1 as filename and 2 as line number.
This causes issues because such lines are very common in practice, and the leading newline alone is enough to trigger go-test matching.

I recommend restricting the go-test pattern:

  1. Replace the \s-+ by a more precise match, e.g. four spaces.
  2. Replace the filename group by something that is likely to be an actual filename (e.g. no spaces or colons).
phst added a commit to phst/go-mode.el that referenced this issue May 10, 2020
Fixes dominikh#361, dominikh#362

Restrict the prefix and filename pattern (Bug dominikh#361), and also allow for a test
name prefix (Bug dominikh#362).

Add regression tests for these bugs.
@phst phst linked a pull request May 10, 2020 that will close this issue
phst added a commit to phst/go-mode.el that referenced this issue May 10, 2020
Fixes dominikh#361, dominikh#362

Restrict the prefix and filename pattern (Bug dominikh#361), and also allow for a test
name prefix (Bug dominikh#362).

Add regression tests for these bugs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant