-
Notifications
You must be signed in to change notification settings - Fork 30.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
inspector: fix StringUtil::CharacterCount for unicodes
`StringUtil::CharacterCount` should return the length of underlying representation storage of a protocol string. `StringUtil::CharacterCount` is only used in DictionaryValue serialization. Only `Network.Headers` is an object type, represented with DictionaryValue. PR-URL: #56788 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Daniel Lemire <[email protected]> Reviewed-By: Kohei Ueno <[email protected]>
- Loading branch information
1 parent
671d058
commit 0edeafd
Showing
7 changed files
with
122 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#include "crdtp/json.h" | ||
#include "gtest/gtest.h" | ||
#include "inspector/node_json.h" | ||
#include "node/inspector/protocol/Protocol.h" | ||
|
||
namespace node { | ||
namespace inspector { | ||
namespace protocol { | ||
namespace { | ||
|
||
TEST(InspectorProtocol, Utf8StringSerDes) { | ||
constexpr const char* kKey = "unicode_key"; | ||
constexpr const char* kValue = "CJK ζ±ε π± π§βπ§βπ§βπ§"; | ||
std::unique_ptr<DictionaryValue> val = DictionaryValue::create(); | ||
val->setString(kKey, kValue); | ||
|
||
std::vector<uint8_t> cbor = val->Serialize(); | ||
std::string json; | ||
crdtp::Status status = | ||
crdtp::json::ConvertCBORToJSON(crdtp::SpanFrom(cbor), &json); | ||
CHECK(status.ok()); | ||
|
||
std::unique_ptr<DictionaryValue> parsed = | ||
DictionaryValue::cast(JsonUtil::parseJSON(json)); | ||
std::string parsed_value; | ||
CHECK(parsed->getString(kKey, &parsed_value)); | ||
CHECK_EQ(parsed_value, std::string(kValue)); | ||
} | ||
|
||
} // namespace | ||
} // namespace protocol | ||
} // namespace inspector | ||
} // namespace node |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Flags: --inspect=0 --experimental-network-inspection | ||
'use strict'; | ||
const common = require('../common'); | ||
|
||
common.skipIfInspectorDisabled(); | ||
|
||
const inspector = require('node:inspector/promises'); | ||
const { Network } = require('node:inspector'); | ||
const test = require('node:test'); | ||
const assert = require('node:assert'); | ||
const { waitUntil } = require('../common/inspector-helper'); | ||
|
||
const session = new inspector.Session(); | ||
session.connect(); | ||
|
||
test('should emit Network.requestWillBeSent with unicode', async () => { | ||
await session.post('Network.enable'); | ||
const expectedValue = 'CJK ζ±ε π± π§βπ§βπ§βπ§'; | ||
|
||
const requestWillBeSentFuture = waitUntil(session, 'Network.requestWillBeSent') | ||
.then(([event]) => { | ||
assert.strictEqual(event.params.request.url, expectedValue); | ||
assert.strictEqual(event.params.request.method, expectedValue); | ||
assert.strictEqual(event.params.request.headers.mKey, expectedValue); | ||
}); | ||
|
||
Network.requestWillBeSent({ | ||
requestId: '1', | ||
timestamp: 1, | ||
wallTime: 1, | ||
request: { | ||
url: expectedValue, | ||
method: expectedValue, | ||
headers: { | ||
mKey: expectedValue, | ||
}, | ||
}, | ||
}); | ||
|
||
await requestWillBeSentFuture; | ||
}); |