diff --git a/lib/sax.js b/lib/sax.js
index 795d607e..140434d9 100644
--- a/lib/sax.js
+++ b/lib/sax.js
@@ -1257,10 +1257,14 @@
case S.PROC_INST_ENDING:
if (c === '>') {
- emitNode(parser, 'onprocessinginstruction', {
- name: parser.procInstName,
- body: parser.procInstBody
- })
+ if (parser.procInstName === '') {
+ strictFail(parser, 'Processing instruction without a name')
+ } else {
+ emitNode(parser, 'onprocessinginstruction', {
+ name: parser.procInstName,
+ body: parser.procInstBody
+ })
+ }
parser.procInstName = parser.procInstBody = ''
parser.state = S.TEXT
} else {
diff --git a/test/processing-instruction.js b/test/processing-instruction.js
new file mode 100644
index 00000000..72d3deab
--- /dev/null
+++ b/test/processing-instruction.js
@@ -0,0 +1,38 @@
+require(__dirname).test({
+ xml: 'body',
+ expect: [
+ [ 'processinginstruction', { name: 'name', body: 'body' } ],
+ [ 'opentagstart', { name: 'xml', attributes: {} } ],
+ [ 'opentag', { name: 'xml', attributes: {}, isSelfClosing: false } ],
+ [ 'text', 'body' ],
+ [ 'closetag', 'xml' ]
+ ],
+ strict: true
+})
+
+require(__dirname).test({
+ xml: 'body',
+ expect: [
+ [ 'processinginstruction', { name: 'name', body: '' } ],
+ [ 'opentagstart', { name: 'xml', attributes: {} } ],
+ [ 'opentag', { name: 'xml', attributes: {}, isSelfClosing: false } ],
+ [ 'text', 'body' ],
+ [ 'closetag', 'xml' ]
+ ],
+ strict: true
+})
+
+require(__dirname).test({
+ xml: '?>body',
+ expect: [
+ [
+ 'error',
+ 'Processing instruction without a name\nLine: 0\nColumn: 4\nChar: >'
+ ],
+ [ 'opentagstart', { name: 'xml', attributes: {} } ],
+ [ 'opentag', { name: 'xml', attributes: {}, isSelfClosing: false } ],
+ [ 'text', 'body' ],
+ [ 'closetag', 'xml' ]
+ ],
+ strict: true
+})