-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
feat: add a newline after commands that don't end their output with one #810
Conversation
* Resolves google#776 Signed-off-by: chankruze <[email protected]>
const eol = Buffer.from('\n', 'utf-8')
if (!entry.data.slice(-1).equals(eol)) {
entry.data = Buffer.concat([entry.data, eol])
} |
@antongolub What's your opinion about this ?
const eol = Buffer.from('\n', 'utf-8');
if (Uint8Array.prototype.slice.call(entry.data, -1)[0] !== eol[0]) {
entry.data = Buffer.concat([entry.data, eol]);
} |
Signed-off-by: chankruze <[email protected]>
cc @antonmedv Uint8Array... Ok, we get some kind of const B = entry.data.constructor
const eol = B.from('\n')
if (entry.data.slice(-1).equal(eol)) {
entry.data = B.concat([entry.data, eol])
}
|
Well, it seems too verbose to modify the value. Let's keep the initial approach. Just move this helper to util.ts and add a test plz. export function ensureEol (buffer: Buffer): Buffer {
if (buffer.toString('utf8', buffer.length - 1) !== '\n') {
return Buffer.concat([buffer, Buffer.from('\n')])
}
return buffer
} |
|
@antongolub sure! will do that.
So, It's not equivalent to I think |
@antongolub what about this approach ? export function ensureEol(buffer: Buffer): Buffer {
if (!buffer.toString('utf8').endsWith('\n')) {
return Buffer.concat([buffer, Buffer.from('\n')])
}
return buffer
} I'm currently writing test. Just to confirm, do I need to write test for both this function and the core behavior or just the core test is good enough ? |
|
@antongolub please review the changes and comment if anything needs to be done. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mention the method
Signed-off-by: chankruze <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Issue: #776