Is there a way to check whether a url is valid glob pattern?
Opened this issue · 3 comments
vivekprm commented
I am trying to test whether a pattern is valid glob. How can we do that?
E.g. "^register/?$" this should return false.
I was trying to test like this but getting true.
package glob
import (
"fmt"
"github.com/gobwas/glob/compiler"
"github.com/gobwas/glob/syntax"
)
func isGlob (str string) bool {
delim := []rune{','}
if str == "" {
return false;
}
ast, err := syntax.Parse(str);
if err != nil {
return false
}
_, err := compiler.Compile(ast, delim)
if err == nil {
return true
}
return false
}
calmh commented
E.g. "^register/?$" this should return false.
But ^register/?$
is a valid glob pattern, it matches ^register/x$
for example... It's also a valid regexp, and as a human I can see that it's likely intended as that and not a glob pattern, but I don't think this package can know that?
vivekprm commented
calmh commented
Regexps and glob patterns are different. I'm not sure why you think ^ and $ are not allowed - they are just normal characters as far as a glob pattern is concerned.
I'm not the author of this package, by the way, just a bystander.