-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Support exclamation mark to create non-matching list in tail plugin #8613
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would love to use ReplaceAll()
instead of the Replace()
function with -1
for readability. Furthermore, \\[!
is a valid pattern matching literal [!
but is now replaced to \\[^
with your change. Even though I think it is unlikely to be used in the wild, the probability is not zero. Could you please check this corner-case!?
@srebhan thanks for the review! So because Go doesn't support negative lookahead in regular expressions I am having a hard time thinking of a clean way to check for this edge case, do you have any suggestions? |
Well
should work according to my test... |
@srebhan So I couldn't get the regex to work exactly like we would want to. I did find another open source project doublestar that supports both double star and !/^ for negation, it does remove the custom logic that globpath has for handling doublestar which is nice. What do you think? @jagularr the code has changed quite a bit from when you reviewed it after my latest change in case you wanted to look at it again as well. |
replace |
@sspaink what's wrong with the regexp I posted? Could you give me an example where it fails!? Requiring an external dependency to replace a regexp seems odd... |
@srebhan The two issues I noticed when you run the playground example you provided: @ssoroka provided a regex that solved the second issue, playground but the first problem where the previous character gets replaced still happens. |
re using a library, glob is used in a lot of different places and I'd really love consistent behavior that–ideally–meet some standard that we are not managing ourselves. It seems too easy to accidentally create our own fork of glob behavior, which it seems is exactly what we've done and now we have to support this old broken behavior... |
@sspaink fixed both with package main
import (
"fmt"
"regexp"
)
func main() {
test := []string {
"lala[!w]ee",
"[!p]laid",
"foo\\[!wja",
"\\[!wbar",
"foo[!abc] and \\[!wbar are wunderbar",
}
re := regexp.MustCompile(`([^\\]?)(\[!)`)
for _, s := range test {
fmt.Printf("%s --> %s\n", s, re.ReplaceAllString(s, "$1[^"))
}
} But if I understand @ssoroka correctly he prefers to use the doublestar-package. Also fine with me. :-) |
@srebhan thank you for the updated regular expression, I've updated the pull request to use the suggested change and it looks like it works without having to change any of the existing tests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
replace string twice to handle edge case
…nfluxdata#8613) * Replace exclamation mark with caret * Update README and use table driven tests * Use ReplaceAll instead * Use doublestar package instead to glob filepath * Add license * Fix order of dependencies * Doc improvement, maybe better then str replace? * Forgot to remove nil from test * Use regex instead of library * Revert unnecessary change * Go back to using library replace string twice to handle edge case
Required for all PRs:
Fixes #7419 by converting
[!
to[^
which allows both characters to be used.The Tail plugin depends on the standard Go function filepath.Glob which uses filepath.Match and this function does not support
!
only^
, evidently this was an oversight during implementation: golang/go#41394. Hopefully in the second version of the filepath package both characters will be supported natively and we can remove this change.Also updated the relevant unit test in globpath_test.go to use table driven tests.
Thanks!