Skip to content

Is there a way to check whether a url is valid glob pattern? #57

@vivekprm

Description

@vivekprm

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
}

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