html-select
Advanced tools
Comparing version 1.1.3 to 1.1.4
@@ -32,11 +32,12 @@ module.exports = function (buf) { | ||
var kv = parts[j].split('='); | ||
key = kv[0].toLowerCase(); | ||
key = kv[0].toLowerCase().trim(); | ||
if (kv.length > 1) { | ||
value = kv.slice(1).join('='); | ||
if (/^"/.test(value)) { | ||
value = value.replace(/^"/, '').replace(/"$/, ''); | ||
if (/^\s*"/.test(value)) { | ||
value = value.replace(/^\s*"/, '').replace(/"\s*$/, ''); | ||
} | ||
else if (/^'/.test(value)) { | ||
value = value.replace(/^'/, '').replace(/'$/, ''); | ||
else if (/^\s*'/.test(value)) { | ||
value = value.replace(/^\s*'/, '').replace(/'\s*$/, ''); | ||
} | ||
else value = value.trim(); | ||
} | ||
@@ -43,0 +44,0 @@ else value = true; |
{ | ||
"name": "html-select", | ||
"version": "1.1.3", | ||
"version": "1.1.4", | ||
"description": "match a tokenized html stream with css selectors", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -63,1 +63,46 @@ var select = require('../'); | ||
}); | ||
test('trailing whitespace attribute', function (t) { | ||
t.plan(2); | ||
var s = select('input[TypE=text]', function (e) { | ||
t.equal(e.name, 'input'); | ||
t.deepEqual(e.attributes, { type: 'text', value: 'xyz' }); | ||
}); | ||
s.write([ 'open', '<html>' ]); | ||
s.write([ 'open', '<body>' ]); | ||
s.write([ 'open', '<input type="submit">' ]); | ||
s.write([ 'open', '<input type="text" value ="xyz">' ]); | ||
s.write([ 'close', '</body>' ]); | ||
s.write([ 'close', '</html>' ]); | ||
s.end(); | ||
}); | ||
test('attribute extra whitespace', function (t) { | ||
t.plan(2); | ||
var s = select('input[TypE=text]', function (e) { | ||
t.equal(e.name, 'input'); | ||
t.deepEqual(e.attributes, { type: 'text', value: 'xyz' }); | ||
}); | ||
s.write([ 'open', '<html>' ]); | ||
s.write([ 'open', '<body>' ]); | ||
s.write([ 'open', '<input type="submit">' ]); | ||
s.write([ 'open', '<input type="text" value = xyz >' ]); | ||
s.write([ 'close', '</body>' ]); | ||
s.write([ 'close', '</html>' ]); | ||
s.end(); | ||
}); | ||
test('attribute whitespace around quotes', function (t) { | ||
t.plan(2); | ||
var s = select('input[TypE=text]', function (e) { | ||
t.equal(e.name, 'input'); | ||
t.deepEqual(e.attributes, { type: 'text', value: 'xyz' }); | ||
}); | ||
s.write([ 'open', '<html>' ]); | ||
s.write([ 'open', '<body>' ]); | ||
s.write([ 'open', '<input type="submit">' ]); | ||
s.write([ 'open', '<input type="text" value = "xyz" >' ]); | ||
s.write([ 'close', '</body>' ]); | ||
s.write([ 'close', '</html>' ]); | ||
s.end(); | ||
}); |
48404
815