fix(pipe): do not store accumulated message as string (#16641)

Accumulated message must be stored raw; otherwise, unicode encoding
will break while trying to decode them.

Fixes #16367
This commit is contained in:
Andrey Lushnikov 2022-08-18 07:53:56 -07:00 committed by GitHub
parent cfe7af79e9
commit 59562de0ec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 5 deletions

View file

@ -22,7 +22,7 @@ import { debugLogger } from '../common/debugLogger';
export class PipeTransport implements ConnectionTransport { export class PipeTransport implements ConnectionTransport {
private _pipeRead: NodeJS.ReadableStream; private _pipeRead: NodeJS.ReadableStream;
private _pipeWrite: NodeJS.WritableStream; private _pipeWrite: NodeJS.WritableStream;
private _pendingMessage = ''; private _pendingBuffers: Buffer[] = [];
private _waitForNextTask = makeWaitForNextTask(); private _waitForNextTask = makeWaitForNextTask();
private _closed = false; private _closed = false;
private _onclose?: () => void; private _onclose?: () => void;
@ -67,10 +67,11 @@ export class PipeTransport implements ConnectionTransport {
_dispatch(buffer: Buffer) { _dispatch(buffer: Buffer) {
let end = buffer.indexOf('\0'); let end = buffer.indexOf('\0');
if (end === -1) { if (end === -1) {
this._pendingMessage += buffer.toString(); this._pendingBuffers.push(buffer);
return; return;
} }
const message = this._pendingMessage + buffer.toString(undefined, 0, end); this._pendingBuffers.push(buffer.slice(0, end));
const message = Buffer.concat(this._pendingBuffers).toString();
this._waitForNextTask(() => { this._waitForNextTask(() => {
if (this.onmessage) if (this.onmessage)
this.onmessage.call(null, JSON.parse(message)); this.onmessage.call(null, JSON.parse(message));
@ -87,6 +88,6 @@ export class PipeTransport implements ConnectionTransport {
start = end + 1; start = end + 1;
end = buffer.indexOf('\0', start); end = buffer.indexOf('\0', start);
} }
this._pendingMessage = buffer.toString(undefined, start); this._pendingBuffers = [buffer.slice(start)];
} }
} }

View file

@ -141,7 +141,6 @@ it('should work with large strings', async ({ page }) => {
}); });
it('should work with large unicode strings', async ({ page, browserName, platform }) => { it('should work with large unicode strings', async ({ page, browserName, platform }) => {
it.fixme(browserName === 'firefox' && platform === 'darwin');
it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/16367' }); it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/16367' });
const expected = '🎭'.repeat(10000); const expected = '🎭'.repeat(10000);