Skip to content
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

Fixed missing Buffer to string conversion. #56

Merged
merged 2 commits into from
Dec 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class Transaction {

add_data (line) {
if (typeof line === 'string') { // This shouldn't ever happen...
line = new Buffer(line, 'binary');
line = Buffer.from(line, 'binary');
}
// check if this is the end of headers line
if (this.header_pos === 0 &&
Expand All @@ -86,7 +86,7 @@ class Transaction {
line.toString('binary').replace(/\r\n$/, '\n'));
}
}
else if (this.header_pos && this.parse_body) {
else if (this.parse_body) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure about this change? This change makes the test fixture different than Haraka/transaction.js.

if (line[0] === 0x2E) line = line.slice(1); // Strip leading "."
let new_line = this.body.parse_more(
line.toString('binary').replace(/\r\n$/, '\n'));
Expand All @@ -95,8 +95,8 @@ class Transaction {
return; // buffering for banners
}

new_line = new_line.replace(/^\./gm, '..').replace(/\r?\n/gm, '\r\n');
line = new Buffer(new_line,'binary');
new_line = new_line.toString('binary').replace(/^\./gm, '..').replace(/\r?\n/gm, '\r\n');
line = Buffer.from(new_line,'binary');
}

if (!this.discard_data) this.message_stream.add_line(line);
Expand Down Expand Up @@ -131,7 +131,7 @@ class Transaction {
data = data.toString('binary')
.replace(/^\./gm, '..')
.replace(/\r?\n/gm, '\r\n');
const line = new Buffer(data, 'binary');
const line = Buffer.from(data, 'binary');

if (!this.discard_data) this.message_stream.add_line(line);
}
Expand Down
12 changes: 11 additions & 1 deletion test/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ describe('transaction', function () {
done();
})

it('can add_data with parse_body = true', (done) => {
const newTrans = transaction.createTransaction('', {"headers":{"max_lines":1000}});
newTrans.parse_body = true;
newTrans.add_data(`From: test@example.com\r\n`);
newTrans.add_data(`\r\n`);
newTrans.add_data(`abcde\r\n`);
newTrans.add_data(`zyxwvu\r\n`);
done();
})

describe('Header', function () {

beforeEach((done) => {
Expand All @@ -60,4 +70,4 @@ describe('transaction', function () {
done();
})
})
})
})
Loading