Skip to content

Commit 2166ab7

Browse files
huntiemeta-codesync[bot]
authored andcommitted
Replace CDP messageStr conversion error with assert (#55041)
Summary: Pull Request resolved: #55041 Follows D89659685. An invalid `string_view` should never be passed to the CDP WebSocket — fail harder via a dev-only assert. Changelog: [Internal] Reviewed By: rubennorte Differential Revision: D90113888 fbshipit-source-id: 9c08567314d2abae7680084182f1f572060601a7
1 parent 32c3d2f commit 2166ab7

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

packages/react-native/React/Inspector/RCTCxxInspectorWebSocketAdapter.mm

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99

1010
#if RCT_DEV || RCT_REMOTE_PROFILE
1111

12+
#import <React/RCTAssert.h>
1213
#import <React/RCTInspector.h>
1314
#import <React/RCTInspectorPackagerConnection.h>
14-
#import <React/RCTLog.h>
1515
#import <React/RCTUtils.h>
1616
#import <SocketRocket/SRWebSocket.h>
1717
#import <jsinspector-modern/InspectorPackagerConnection.h>
@@ -22,7 +22,11 @@
2222
namespace {
2323
NSString *NSStringFromUTF8StringView(std::string_view view)
2424
{
25-
return [[NSString alloc] initWithBytes:(const char *)view.data() length:view.size() encoding:NSUTF8StringEncoding];
25+
NSString *result = [[NSString alloc] initWithBytes:(const char *)view.data()
26+
length:view.size()
27+
encoding:NSUTF8StringEncoding];
28+
RCTAssert(result != nil, @"string_view contains invalid UTF-8 bytes");
29+
return result;
2630
}
2731
} // namespace
2832
@interface RCTCxxInspectorWebSocketAdapter () <SRWebSocketDelegate> {
@@ -47,9 +51,6 @@ - (void)send:(std::string_view)message
4751
{
4852
__weak RCTCxxInspectorWebSocketAdapter *weakSelf = self;
4953
NSString *messageStr = NSStringFromUTF8StringView(message);
50-
if (messageStr == nil) {
51-
RCTLogError(@"Failed to convert CDP message string to NSString, message will be dropped!");
52-
}
5354
dispatch_async(dispatch_get_main_queue(), ^{
5455
RCTCxxInspectorWebSocketAdapter *strongSelf = weakSelf;
5556
if (strongSelf != nullptr) {

0 commit comments

Comments
 (0)