Skip to content
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
8 changes: 4 additions & 4 deletions src/inspector/node_string.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,15 @@ size_t StringUtil::CharacterCount(const std::string_view s) {
}

String Binary::toBase64() const {
MaybeStackBuffer<char> buffer;
size_t str_len = simdutf::base64_length_from_binary(bytes_->size());
buffer.SetLength(str_len);
size_t expected_base64_length =
simdutf::base64_length_from_binary(bytes_->size());
MaybeStackBuffer<char> buffer(expected_base64_length);

size_t len =
simdutf::binary_to_base64(reinterpret_cast<const char*>(bytes_->data()),
bytes_->size(),
buffer.out());
CHECK_EQ(len, str_len);
CHECK_EQ(len, expected_base64_length);
return buffer.ToString();
}

Expand Down
24 changes: 19 additions & 5 deletions test/parallel/test-inspector-network-data-received.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ const assert = require('node:assert');
const { waitUntil } = require('../common/inspector-helper');
const { setTimeout } = require('node:timers/promises');

// The complete payload string received by the network agent
const payloadString = `Hello, world${'.'.repeat(4096)}`;

const session = new inspector.Session();
session.connect();
session.post('Network.enable');
Expand Down Expand Up @@ -67,9 +70,20 @@ async function triggerNetworkEvents(requestId, charset) {
});
await setTimeout(1);

Network.loadingFinished({
// Test inspector binary conversions with large input
const chunk3 = Buffer.allocUnsafe(4096).fill('.');
Network.dataReceived({
requestId,
timestamp: 5,
dataLength: chunk3.byteLength,
encodedDataLength: chunk3.byteLength,
data: chunk3,
});
await setTimeout(1);

Network.loadingFinished({
requestId,
timestamp: 6,
});
}

Expand Down Expand Up @@ -116,7 +130,7 @@ test('should stream Network.dataReceived with data chunks', async () => {

const data = Buffer.concat(chunks);
assert.strictEqual(data.byteLength, totalDataLength, data);
assert.strictEqual(data.toString('utf8'), 'Hello, world');
assert.strictEqual(data.toString('utf8'), payloadString);
});

test('Network.streamResourceContent should send all buffered chunks', async () => {
Expand All @@ -131,7 +145,7 @@ test('Network.streamResourceContent should send all buffered chunks', async () =
const { bufferedData } = await session.post('Network.streamResourceContent', {
requestId,
});
assert.strictEqual(Buffer.from(bufferedData, 'base64').toString('utf8'), 'Hello, world');
assert.strictEqual(Buffer.from(bufferedData, 'base64').toString('utf8'), payloadString);
});

test('Network.streamResourceContent should reject if request id not found', async () => {
Expand All @@ -158,7 +172,7 @@ test('Network.getResponseBody should send all buffered binary data', async () =>
requestId,
});
assert.strictEqual(base64Encoded, true);
assert.strictEqual(body, Buffer.from('Hello, world').toString('base64'));
assert.strictEqual(body, Buffer.from(payloadString).toString('base64'));
});

test('Network.getResponseBody should send all buffered text data', async () => {
Expand All @@ -174,5 +188,5 @@ test('Network.getResponseBody should send all buffered text data', async () => {
requestId,
});
assert.strictEqual(base64Encoded, false);
assert.strictEqual(body, 'Hello, world');
assert.strictEqual(body, payloadString);
});
Loading