Skip to content

Commit

Permalink
Fix capturing selector with empty string as value
Browse files Browse the repository at this point in the history
  • Loading branch information
lauriro committed Feb 7, 2023
1 parent e5cef80 commit 92f252e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion selector.js
Expand Up @@ -69,7 +69,7 @@
,
selectorMap[op == ":" ? key : op] ||
"(a=_.getAttribute(a))" +
(fn ? "&&" + selectorMap[fn] : val ? "==v" : "")
(fn ? "&&" + selectorMap[fn] : val ? "==v" : "!==null")
)
return ""
})
Expand Down
7 changes: 7 additions & 0 deletions test/index-spec.js
Expand Up @@ -300,6 +300,13 @@ describe("DOM lite", function() {
assert.equal(h1.getAttribute("ID"), "123")
assert.equal(h1.getAttribute("ID2"), "321")

h1.setAttribute("id3", "")
assert.equal(h1.hasAttribute("ID3"), true)
assert.equal(h1.getAttribute("ID3"), "")
assert.equal(h1.matches("[ID3]"), true)
assert.equal(h1.matches("[ID3='']"), true)
h1.removeAttribute("id3")

h1.removeAttribute("id2")
assert.equal(h1.getAttribute("id"), "123")
assert.equal(h1.getAttribute("id2"), null)
Expand Down
10 changes: 10 additions & 0 deletions test/selector-spec.js
Expand Up @@ -198,6 +198,16 @@ describe("Selectors", function() {
assert.equal(s2.matches('[data-x4="a,b)"]'), true)
assert.equal(s2.matches('[data-x4="a,b("]'), false)

assert.equal(s2.matches('[data-x5]'), false)
assert.equal(s2.matches('[data-x5=""]'), false)
assert.equal(s2.matches("[data-x5='']"), false)
s2.setAttribute("data-x5", "")
assert.equal(s2.matches('[data-x5]'), true)
assert.equal(s2.matches('[data-x5=""]'), true)
assert.equal(s2.matches("[data-x5='']"), true)
assert.equal(s2.matches('[data-x5][data-x5=""]'), true)
assert.equal(s2.matches("[data-x5][data-x5='']"), true)

assert.equal(s2.matches('div, [data-x1="a,b]"]'), true)
assert.equal(s2.matches('div, [data-x1="a,b["]'), false)
assert.equal(s2.matches('div, [data-x2="a,b["]'), true)
Expand Down

0 comments on commit 92f252e

Please sign in to comment.