File tree Expand file tree Collapse file tree 2 files changed +16
-0
lines changed Expand file tree Collapse file tree 2 files changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -378,6 +378,12 @@ public void MergeInto(Baggage destination)
378378 ThrowHelper . ThrowArgumentNullException ( nameof ( destination ) ) ;
379379 }
380380
381+ if ( ReferenceEquals ( this , destination ) )
382+ {
383+ // We're trying to merge with ourselves
384+ return ;
385+ }
386+
381387 var sourceItems = _items ;
382388
383389 if ( sourceItems is null || sourceItems . Count == 0 )
Original file line number Diff line number Diff line change @@ -168,4 +168,14 @@ public void MergeInto_AddsAndReplacesItems()
168168 baggage1 . GetValueOrDefault ( "key1" ) . Should ( ) . Be ( "new value" ) ;
169169 baggage1 . GetValueOrDefault ( "key2" ) . Should ( ) . Be ( "value2" ) ;
170170 }
171+
172+ [ Fact ]
173+ public void MergeInto_SameInstance ( )
174+ {
175+ var baggage = new Baggage { { "key1" , "value1" } } ;
176+
177+ baggage . MergeInto ( baggage ) ;
178+ baggage . Count . Should ( ) . Be ( 1 ) ;
179+ baggage . GetValueOrDefault ( "key1" ) . Should ( ) . Be ( "value1" ) ;
180+ }
171181}
You can’t perform that action at this time.
0 commit comments