You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Calling path.Match("malformed[", "file.txt") returns a syntax error in pattern since the bracket is not balanced.
What did you see instead?
In the call path.Match("malformed[", "file.txt"), only the first rune of the pattern needs to be inspected to see that the pattern does not match the given file name.
Therefore no error is reported in this case.
The error would be reported for path.Match("malformed[", "malformed_") though.
Because of this implementation, it is not possible to check a pattern for syntax errors by just calling path.Match(pattern, ""), which I had expected, given the wording of the documentation, which says:
The only possible returned error is ErrBadPattern, when pattern is malformed.
I had thought that when pattern is malformed would mean iff pattern is malformed.
It would be helpful if the documentation mentioned the exact error conditions, since they were surprising, at least to me. Maybe like this:
The only possible returned error is ErrBadPattern, when pattern is malformed and the malformed part of the pattern is actually necessary to determine the match.
This is still imprecise since it doesn't mention that pattern matching starts from the beginning of the string, but at least it provides a hint. If the implementation were to first check the first and the last character of the pattern and the subject, it would still be possible that path.Match("mal[formed", "m.x") skipped the error handling.
The text was updated successfully, but these errors were encountered:
What version of Go are you using (
go version
)?go version go1.12.1 windows/amd64
Does this issue reproduce with the latest release?
yes.
What did you do?
read https://godoc.org/path#Match
https://play.golang.org/p/pdUEQ9VZniG
What did you expect to see?
Calling
path.Match("malformed[", "file.txt")
returns asyntax error in pattern
since the bracket is not balanced.What did you see instead?
In the call
path.Match("malformed[", "file.txt")
, only the first rune of the pattern needs to be inspected to see that the pattern does not match the given file name.Therefore no error is reported in this case.
The error would be reported for
path.Match("malformed[", "malformed_")
though.Because of this implementation, it is not possible to check a pattern for syntax errors by just calling
path.Match(pattern, "")
, which I had expected, given the wording of the documentation, which says:I had thought that when pattern is malformed would mean iff pattern is malformed.
It would be helpful if the documentation mentioned the exact error conditions, since they were surprising, at least to me. Maybe like this:
This is still imprecise since it doesn't mention that pattern matching starts from the beginning of the string, but at least it provides a hint. If the implementation were to first check the first and the last character of the pattern and the subject, it would still be possible that
path.Match("mal[formed", "m.x")
skipped the error handling.The text was updated successfully, but these errors were encountered: