Skip to content

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

@phst

Description

@phst

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions