Skip to content
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

Attribute value of zero #25

Closed
suntong opened this issue Dec 12, 2016 · 2 comments
Closed

Attribute value of zero #25

suntong opened this issue Dec 12, 2016 · 2 comments

Comments

@suntong
Copy link
Contributor

suntong commented Dec 12, 2016

Is this claim to be true:

using quotation marks around an attribute value is required only if this value is not a valid identifier

-- taken from here

I have a multiple attribute selector as "table[border=0][cellpadding=0][cellspacing=0]", and cascadia is failing with the following message:

panic: expected identifier, found 0 instead

goroutine 1 [running]:
panic(0x749a80, 0xc420075ec0)
        /usr/local/go/src/runtime/panic.go:500 +0x1a1
github.com/andybalholm/cascadia.MustCompile(0x7ffe2d3262ea, 0x1b, 0x0)
        /...gopath/src/github.com/andybalholm/cascadia/selector.go:59 +0x7e
...

At first I thought it was issues #24, but it turns out to be zero value of specified attribute. I.e., if I change the CSS selector to table[border="0"][cellpadding="0"][cellspacing="0"], it will work.

Do you think it is worthwhile for you to double-check please? I assume there's a problem because xidel handles table[border=0][cellpadding=0][cellspacing=0] without any problem. Thx.

@suntong
Copy link
Contributor Author

suntong commented Dec 12, 2016

PS, here is how I tested it, FYI,

$ echo '<table border="0" cellpadding="0" cellspacing="0" style="table-layout: fixed; width: 100%; border: 0 dashed; border-color: #FFFFFF"><tr style="height:64px">aaa</tr></table>' | cascadia -i -o -c 'table[border="0"][cellpadding="0"][cellspacing="0"]'
1 elements for 'table[border="0"][cellpadding="0"][cellspacing="0"]':
<table border="0" cellpadding="0" cellspacing="0" style="table-layout: fixed; width: 100%; border: 0 dashed; border-color: #FFFFFF"><tbody><tr style="height:64px"></tr></tbody></table>

That cascadia command above is what I build a thin wrapper around you cascadia package -- https://github.com/suntong/cascadia.

If you could mention that in your readme file, that'd be very appreciated, and I believe it might help a lot of people. Thx.

@andybalholm
Copy link
Owner

The problem is that 0 is not a valid identifier. An identifier must begin with a letter.

Safari doesn't accept the selector in your example either:

> document.querySelector("table[border=0][cellpadding=0][cellspacing=0]")
< SyntaxError (DOM Exception 12): The string did not match the expected pattern.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants