fix: Fix non-tty container message parsing

This had a bug where it was using the `in` operator on a list. It may
have worked for some cases, but would have failed for others.

Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
This commit is contained in:
Cameron Diver 2019-04-02 10:07:28 +01:00
parent e148ce0529
commit 760b18dd2a
No known key found for this signature in database
GPG Key ID: 49690ED87032539F

View File

@ -72,10 +72,13 @@ export class ContainerLogs extends (EventEmitter as {
private static extractMessage(
msgBuf: Buffer,
): { message: string; timestamp: number } | null {
): { message: string; timestamp: number } | undefined {
// Non-tty message format from:
// https://docs.docker.com/engine/api/v1.30/#operation/ContainerAttach
if (msgBuf[0] in [0, 1, 2] && _.every(msgBuf.slice(1, 7), c => c === 0)) {
if (
_.includes([0, 1, 2], msgBuf[0]) &&
_.every(msgBuf.slice(1, 7), c => c === 0)
) {
// Take the header from this message, and parse it as normal
msgBuf = msgBuf.slice(8);
}
@ -91,7 +94,7 @@ export class ContainerLogs extends (EventEmitter as {
message: logLine.substr(space + 1),
};
}
return null;
return;
}
}