mirror of
https://github.com/ericchiang/pup
synced 2024-11-28 02:48:16 +00:00
class selector fixed
This commit is contained in:
parent
1aa3770b59
commit
3e26ed725f
2
main.go
2
main.go
@ -11,7 +11,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
const VERSION string = "0.1.0"
|
const VERSION string = "0.1.1"
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// Flags
|
// Flags
|
||||||
|
@ -42,7 +42,7 @@ func parseAttrField(command string) (attrKey string, matcher *regexp.Regexp,
|
|||||||
attrKeyLen := len(attrKey)
|
attrKeyLen := len(attrKey)
|
||||||
switch attrKey[attrKeyLen-1] {
|
switch attrKey[attrKeyLen-1] {
|
||||||
case '~':
|
case '~':
|
||||||
matcherString = fmt.Sprintf(`[^\s]%s[$\s]`, attrVal)
|
matcherString = fmt.Sprintf(`\b%s\b`, attrVal)
|
||||||
case '$':
|
case '$':
|
||||||
matcherString = fmt.Sprintf("%s$", attrVal)
|
matcherString = fmt.Sprintf("%s$", attrVal)
|
||||||
case '^':
|
case '^':
|
||||||
@ -67,18 +67,27 @@ func (s *Selector) setFieldValue(f selectorField, v string) error {
|
|||||||
if v == "" {
|
if v == "" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
switch f {
|
||||||
|
case ClassField:
|
||||||
|
r, err := regexp.Compile(fmt.Sprintf(`\b%s\b`, v))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
s.Attrs["class"] = r
|
||||||
|
case IDField:
|
||||||
r, err := regexp.Compile(fmt.Sprintf("^%s$", v))
|
r, err := regexp.Compile(fmt.Sprintf("^%s$", v))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
switch f {
|
|
||||||
case ClassField:
|
|
||||||
s.Attrs["class"] = r
|
|
||||||
case IDField:
|
|
||||||
s.Attrs["id"] = r
|
s.Attrs["id"] = r
|
||||||
case NameField:
|
case NameField:
|
||||||
|
r, err := regexp.Compile(fmt.Sprintf("^%s$", v))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
s.Name = r
|
s.Name = r
|
||||||
case AttrField:
|
case AttrField:
|
||||||
|
// Attribute fields are a little more complicated
|
||||||
keystring, matcher, err := parseAttrField(v)
|
keystring, matcher, err := parseAttrField(v)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -94,6 +103,7 @@ func NewSelector(s string) (*Selector, error) {
|
|||||||
selector := &Selector{nil, attrs}
|
selector := &Selector{nil, attrs}
|
||||||
nextField := NameField
|
nextField := NameField
|
||||||
start := 0
|
start := 0
|
||||||
|
// Parse the selector character by character
|
||||||
for i, c := range s {
|
for i, c := range s {
|
||||||
switch c {
|
switch c {
|
||||||
case '.':
|
case '.':
|
||||||
|
Loading…
Reference in New Issue
Block a user