Skip to content

Commit 11a1d87

Browse files
bohdanprogjakex7
andauthored
fix: handle error when defining a nil reference (#2717)
# Summary That PR helped to solve issue #2715 This issue arises on the iOS platform because `NSMutableDictionary<NSString *, RNSVGNode *>` does not allow nil keys or values. On Android, however, the `Map<String, VirtualView>` implementation does allow null keys, which prevents this issue from occurring there. To address the iOS issue, we handle nil values for elements such as `clipPaths, templates, painters, markers, masks, and filters`. Managing `nil` values in `RNSVGSvgView.mm` is practical because the `define*` method is used in multiple locations. --------- Co-authored-by: Jakub Grzywacz <kontakt@jakubgrzywacz.pl> Co-authored-by: Jakub Grzywacz <jakub.grzywacz@swmansion.com>
1 parent 62d496b commit 11a1d87

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

apple/Elements/RNSVGSvgView.mm

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,9 @@ - (void)reactSetInheritedBackgroundColor:(RNSVGColor *)inheritedBackgroundColor
402402

403403
- (void)defineClipPath:(__kindof RNSVGNode *)clipPath clipPathName:(NSString *)clipPathName
404404
{
405+
if (!clipPathName) {
406+
return;
407+
}
405408
if (!_clipPaths) {
406409
_clipPaths = [[NSMutableDictionary alloc] init];
407410
}
@@ -415,6 +418,9 @@ - (RNSVGNode *)getDefinedClipPath:(NSString *)clipPathName
415418

416419
- (void)defineTemplate:(RNSVGNode *)definedTemplate templateName:(NSString *)templateName
417420
{
421+
if (!templateName) {
422+
return;
423+
}
418424
if (!_templates) {
419425
_templates = [[NSMutableDictionary alloc] init];
420426
}
@@ -428,6 +434,9 @@ - (RNSVGNode *)getDefinedTemplate:(NSString *)templateName
428434

429435
- (void)definePainter:(RNSVGPainter *)painter painterName:(NSString *)painterName
430436
{
437+
if (!painterName) {
438+
return;
439+
}
431440
if (!_painters) {
432441
_painters = [[NSMutableDictionary alloc] init];
433442
}
@@ -441,6 +450,9 @@ - (RNSVGPainter *)getDefinedPainter:(NSString *)painterName
441450

442451
- (void)defineMarker:(RNSVGMarker *)marker markerName:(NSString *)markerName
443452
{
453+
if (!markerName) {
454+
return;
455+
}
444456
if (!_markers) {
445457
_markers = [[NSMutableDictionary alloc] init];
446458
}
@@ -454,6 +466,9 @@ - (RNSVGMarker *)getDefinedMarker:(NSString *)markerName
454466

455467
- (void)defineMask:(RNSVGMask *)mask maskName:(NSString *)maskName
456468
{
469+
if (!maskName) {
470+
return;
471+
}
457472
if (!_masks) {
458473
_masks = [[NSMutableDictionary alloc] init];
459474
}
@@ -467,6 +482,9 @@ - (RNSVGMask *)getDefinedMask:(NSString *)maskName
467482

468483
- (void)defineFilter:(RNSVGFilter *)filter filterName:(NSString *)filterName
469484
{
485+
if (!filterName) {
486+
return;
487+
}
470488
if (!_filters) {
471489
_filters = [[NSMutableDictionary alloc] init];
472490
}

0 commit comments

Comments
 (0)