@@ -329,6 +329,42 @@ TEST(diagrams_plantuml) {
329329 PASS ();
330330}
331331
332+ /* #2818: a sequence message to or from the diagram edge (`A ->: x`, `A <-: x`,
333+ * `[-> A: x`) and a declaration with an unclosed bracket have no operand id;
334+ * they used to read an uninitialized one and crash the index worker. The
335+ * declaration sits in its own diagram: a `class` line makes a diagram a class
336+ * diagram, where `->` is an arrow rather than a sequence message. */
337+ TEST (diagrams_plantuml_edge_messages ) {
338+ CBMFileResult * r = dg_file ("@startuml\n"
339+ "participant Alice\n"
340+ "Alice ->: out\n"
341+ "Alice <-: in\n"
342+ "[-> Alice: from the edge\n"
343+ "Alice -> Bob : hello\n"
344+ "@enduml\n"
345+ "@startuml\n"
346+ "class [Unclosed\n"
347+ "@enduml\n" ,
348+ "docs/edge.puml" );
349+ ASSERT_NOT_NULL (r );
350+ ASSERT_STR_EQ (dg_prop (dg_def (r , "edge#diagram-1" ), "diagram_kind" ), "sequence" );
351+ ASSERT_STR_EQ (dg_prop (dg_def (r , "edge#diagram-2" ), "diagram_kind" ), "class" );
352+ ASSERT_NOT_NULL (dg_def (r , "edge#diagram-1.Alice" ));
353+ ASSERT_NOT_NULL (dg_def (r , "edge#diagram-1.Bob" ));
354+ ASSERT_EQ (r -> diagram_arrows .count , 1 );
355+ ASSERT_EQ (dg_arrows (r , "#diagram-1.Alice" , "#diagram-1.Bob" , "message" , "hello" ), 1 );
356+ int elements = 0 ;
357+ for (int i = 0 ; i < r -> defs .count ; i ++ ) {
358+ const char * label = r -> defs .items [i ].label ;
359+ if (label && strcmp (label , "DiagramElement" ) == 0 ) {
360+ elements ++ ;
361+ }
362+ }
363+ ASSERT_EQ (elements , 2 );
364+ cbm_free_result (r );
365+ PASS ();
366+ }
367+
332368TEST (diagrams_dot ) {
333369 CBMFileResult * r =
334370 dg_file ("digraph G {\n"
@@ -1101,6 +1137,7 @@ SUITE(diagrams) {
11011137 RUN_TEST (diagrams_mermaid_kinds );
11021138 RUN_TEST (diagrams_other_fences );
11031139 RUN_TEST (diagrams_plantuml );
1140+ RUN_TEST (diagrams_plantuml_edge_messages );
11041141 RUN_TEST (diagrams_dot );
11051142 RUN_TEST (diagrams_d2 );
11061143 RUN_TEST (diagrams_drawio );
0 commit comments