-
Notifications
You must be signed in to change notification settings - Fork 519
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Exec stdin might lost data if pass in Readable.from(string)
#1772
Comments
Happy to take a PR with a unit test to repro this and either fix that you prefer. |
Here is a small reproduction: 'use strict';
const { deepStrictEqual } = require('node:assert');
const { Readable } = require('node:stream');
const { test } = require('node:test');
const { WebSocketHandler } = require('./dist/web-socket-handler');
test('repro', () => {
const { promise, resolve } = Promise.withResolvers();
const stream = new Readable({ read() {} });
const ws = {
close() {},
send(data) {
deepStrictEqual(data, Buffer.from([0x0f, 0xe2, 0x98, 0x83]));
resolve();
}
};
stream.setEncoding('utf8');
stream.push('☃');
WebSocketHandler.handleStandardInput(ws, stream, 0x0f);
return promise;
}); I'll work on a fix. |
cjihrig
added a commit
to cjihrig/javascript
that referenced
this issue
Sep 28, 2024
This commit updates the way the WebSocketHandler processes string data. Prior to this commit, it relied on string lengths, which does not properly account for multi-byte characters. This commit changes the logic to account for string encodings that contain multi-byte characters. Fixes: kubernetes-client#1772
I think this can be closed since #1900 was merged. I'm a bit surprised that it didn't auto-close. EDIT: Maybe it didn't auto-close since the PR targeted the release-1.x branch. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
javascript/src/web-socket-handler.ts
Line 58 in b4fd82f
Current implementation assume stdin is always a binary stream, but it does not really check the type. So if pass
Readable.from(string)
as stdin, most time it works, unless the string contains non-ASCII characters, in such case,data
is string anddata.length
is number of UTF16 code units, which will smaller than the number of UTF8 code units or bytes.I suggest the implementation should either deal with the string case, or just throw type error if not buffer.
The text was updated successfully, but these errors were encountered: