Skip to content
This repository was archived by the owner on Oct 5, 2023. It is now read-only.

Commit c16bcf1

Browse files
committed
support tag names with hyphen
1 parent d154cdc commit c16bcf1

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function parse(xml) {
6969

7070
function tag() {
7171
debug('tag %j', xml);
72-
var m = match(/^<([\w+:.]+)\s*/);
72+
var m = match(/^<([\w-:.]+)\s*/);
7373
if (!m) return;
7474

7575
// name
@@ -103,7 +103,7 @@ function parse(xml) {
103103
}
104104

105105
// closing
106-
match(/^<\/[\w:.]+>\s*/);
106+
match(/^<\/[\w-:.]+>\s*/);
107107

108108
return node;
109109
}

test/index.js

+29-1
Original file line numberDiff line numberDiff line change
@@ -231,4 +231,32 @@ it('should support tags with a dot', function () {
231231
}],
232232
content: ""
233233
})
234-
})
234+
})
235+
236+
it('should support tags with hyphen', function () {
237+
var node = parse(
238+
'<root>' +
239+
'<data-field1>val1</data-field1>' +
240+
'<data-field2>val2</data-field2>' +
241+
'</root>'
242+
);
243+
node.root.should.eql({
244+
name: 'root',
245+
attributes: {},
246+
content: '',
247+
children: [
248+
{
249+
name: 'data-field1',
250+
attributes: {},
251+
children: [],
252+
content: 'val1'
253+
},
254+
{
255+
name: 'data-field2',
256+
attributes: {},
257+
children: [],
258+
content: 'val2'
259+
}
260+
]
261+
});
262+
});

0 commit comments

Comments
 (0)