mirror of
https://github.com/msva/lua-htmlparser.git
synced 2024-11-27 12:44:22 +00:00
Merge pull request #30 from ljie-PI/master
make it work when there's a dot in the attribute selector
This commit is contained in:
commit
a021c46018
@ -149,11 +149,25 @@ local function select(self, s)
|
||||
childrenonly = false
|
||||
if part == "*" then goto nextpart end
|
||||
local excludes, filter = Set:new()
|
||||
for t, w in string.gmatch(part,
|
||||
local halfword = ""
|
||||
for t, w, c in string.gmatch(part,
|
||||
"([:%[#.]?)" .. -- t = an optional :, [, #, or .
|
||||
"([^:%(%[#.%]%)]+)" .. -- w = 1 or more of anything not :, (, [, #, ., ], or )
|
||||
"%]?%)?" -- followed by an uncaptured optional ] and/or )
|
||||
"(%]?)%)?" -- followed by an uncaptured optional ] and/or )
|
||||
) do
|
||||
-- this if..elseif.. block will match the pattern like "[src='aaa.jpg']"
|
||||
if t == "[" and c ~= "]" then
|
||||
halfword = t .. w
|
||||
goto nextw
|
||||
elseif c == "" and halfword ~= "" then
|
||||
halfword = halfword .. t .. w
|
||||
goto nextw
|
||||
elseif t ~= "[" and c == "]" then
|
||||
halfword = halfword .. t .. w .. c
|
||||
t, w = "[", string.sub(halfword, 2, -2)
|
||||
halfword = ""
|
||||
end
|
||||
|
||||
if t == ":" then filter = w goto nextw end
|
||||
local matched = match(t, w)
|
||||
if filter == "not" then
|
||||
|
@ -85,7 +85,7 @@ function test_attr_equal()
|
||||
<n a1 a2= a3='' a4=""
|
||||
a5='a"5"' a6="a'6'" a7='#.[] :()' a8='|*+-=?$^%&/'
|
||||
a9=a9
|
||||
a10></n>
|
||||
a10 a11="a11.js.jpg"></n>
|
||||
]])
|
||||
assert_equal(1, #tree.nodes, "top level")
|
||||
assert(tree("[a1='']")[1], "a1=''")
|
||||
@ -102,6 +102,8 @@ function test_attr_equal()
|
||||
assert(tree("[a9='a9']")[1], "a9='a9'")
|
||||
assert(tree("[a10='']")[1], "a10=''")
|
||||
assert(tree("[a10=]")[1], "a10=")
|
||||
-- An excepton for a7. Some times we may select javascript or img nodes with attr selector [src="a.js"] or [src="a.jpg"]
|
||||
assert(tree("[a11='a11.js.jpg']")[1], "a11=")
|
||||
end
|
||||
|
||||
function test_attr_notequal()
|
||||
|
Loading…
Reference in New Issue
Block a user