-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Should not allow 'end' events to happen more than once
Likely root cause of: zkat/pacote#151 isaacs/node-tar#180 laravel/homestead#866
- Loading branch information
Showing
2 changed files
with
25 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict' | ||
const t = require('tap') | ||
const MP = require('../') | ||
|
||
const butterfly = Buffer.from([0x61, 0xf0, 0x9f, 0xa6, 0x8b, 0xf0]) | ||
const mp = new MP({ encoding: 'utf8' }) | ||
|
||
let sawEnd = 0 | ||
mp.on('end', () => | ||
t.equal(sawEnd++, 0, 'should not have seen the end yet')) | ||
|
||
mp.once('data', () => { | ||
mp.once('data', () => { | ||
mp.once('data', () => mp.end()) | ||
mp.end() | ||
}) | ||
mp.end(butterfly.slice(3)) | ||
}) | ||
mp.end(butterfly.slice(0, 3)) | ||
|
||
t.equal(sawEnd, 1, 'should see end exactly once') |