Skip to content

Commit

Permalink
Do not use the deprecated Buffer() constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
lpinca committed Oct 13, 2018
1 parent 5aee216 commit dc41a3a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"README.md"
],
"devDependencies": {
"safer-buffer": "^2.1.2",
"standard": "^8.6.0",
"tap": "^10.5.1"
}
Expand Down
3 changes: 2 additions & 1 deletion test/not-string.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
var Buffer = require('safer-buffer').Buffer
var parser = require('../').parser(true)
var t = require('tap')
t.plan(1)
parser.onopentag = function (node) {
t.same(node, { name: 'x', attributes: {}, isSelfClosing: false })
}
var xml = new Buffer('<x>y</x>')
var xml = Buffer.from('<x>y</x>')
parser.write(xml).close()
27 changes: 14 additions & 13 deletions test/utf8-split.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
var Buffer = require('safer-buffer').Buffer
var tap = require('tap')
var saxStream = require('../lib/sax').createStream()

var b = new Buffer('误')
var b = Buffer.from('误')

saxStream.on('text', function (text) {
tap.equal(text, b.toString())
})

saxStream.write(new Buffer('<test><a>'))
saxStream.write(Buffer.from('<test><a>'))
saxStream.write(b.slice(0, 1))
saxStream.write(b.slice(1))
saxStream.write(new Buffer('</a><b>'))
saxStream.write(Buffer.from('</a><b>'))
saxStream.write(b.slice(0, 2))
saxStream.write(b.slice(2))
saxStream.write(new Buffer('</b><c>'))
saxStream.write(Buffer.from('</b><c>'))
saxStream.write(b)
saxStream.write(new Buffer('</c>'))
saxStream.write(Buffer.concat([new Buffer('<d>'), b.slice(0, 1)]))
saxStream.end(Buffer.concat([b.slice(1), new Buffer('</d></test>')]))
saxStream.write(Buffer.from('</c>'))
saxStream.write(Buffer.concat([Buffer.from('<d>'), b.slice(0, 1)]))
saxStream.end(Buffer.concat([b.slice(1), Buffer.from('</d></test>')]))

var saxStream2 = require('../lib/sax').createStream()

saxStream2.on('text', function (text) {
tap.equal(text, '�')
})

saxStream2.write(new Buffer('<root>'))
saxStream2.write(new Buffer('<e>'))
saxStream2.write(new Buffer([0xC0]))
saxStream2.write(new Buffer('</e>'))
saxStream2.write(Buffer.concat([new Buffer('<f>'), b.slice(0, 1)]))
saxStream2.write(new Buffer('</root>'))
saxStream2.write(Buffer.from('<root>'))
saxStream2.write(Buffer.from('<e>'))
saxStream2.write(Buffer.from([0xC0]))
saxStream2.write(Buffer.from('</e>'))
saxStream2.write(Buffer.concat([Buffer.from('<f>'), b.slice(0, 1)]))
saxStream2.write(Buffer.from('</root>'))
saxStream2.end()

0 comments on commit dc41a3a

Please sign in to comment.