Merge pull request #11774 from nitsakh/fix-invalid-utf

Handle invalid utf8 characters for debugger
This commit is contained in:
shelley vohr 2018-02-05 12:44:41 -05:00 committed by GitHub
commit e6a5990b95
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -134,8 +134,7 @@ describe('debugger module', () => {
}) })
}) })
// TODO(deepak1556): Find a way to enable this spec. it('handles valid unicode characters in message', (done) => {
xit('handles invalid unicode characters in message', (done) => {
try { try {
w.webContents.debugger.attach() w.webContents.debugger.attach()
} catch (err) { } catch (err) {
@ -146,12 +145,39 @@ describe('debugger module', () => {
if (method === 'Network.loadingFinished') { if (method === 'Network.loadingFinished') {
w.webContents.debugger.sendCommand('Network.getResponseBody', { w.webContents.debugger.sendCommand('Network.getResponseBody', {
requestId: params.requestId requestId: params.requestId
}, () => { }, (_, data) => {
assert.equal(data.body, '\u0024')
done() done()
}) })
} }
}) })
server = http.createServer((req, res) => {
res.setHeader('Content-Type', 'text/plain; charset=utf-8')
res.end('\u0024')
})
server.listen(0, '127.0.0.1', () => {
w.webContents.debugger.sendCommand('Network.enable')
w.loadURL(`http://127.0.0.1:${server.address().port}`)
})
})
it('does not crash for invalid unicode characters in message', (done) => {
try {
w.webContents.debugger.attach()
} catch (err) {
done(`unexpected error : ${err}`)
}
w.webContents.debugger.on('message', (event, method, params) => {
// loadingFinished indicates that page has been loaded and it did not
// crash because of invalid UTF-8 data
if (method === 'Network.loadingFinished') {
done()
}
})
server = http.createServer((req, res) => { server = http.createServer((req, res) => {
res.setHeader('Content-Type', 'text/plain; charset=utf-8') res.setHeader('Content-Type', 'text/plain; charset=utf-8')
res.end('\uFFFF') res.end('\uFFFF')