@@ -865,16 +865,28 @@ TEST(php_inline_html_markup_never_reaches_graph_issue2000) {
865865}
866866
867867/* The mask hands back the caller's buffer, uncopied, when nothing needs
868- * rewriting, and a same-length rewrite otherwise. */
868+ * rewriting, and a same-length rewrite otherwise. The pointer alone cannot
869+ * tell copy-on-write from an eager copy, so the arena's allocation total is
870+ * sampled around each call: no bytes for `plain` and `quoted`, a copy for
871+ * `mixed`. */
869872TEST (php_inline_html_mask_copies_only_on_write_issue2000 ) {
870873 CBMArena arena ;
871874 cbm_arena_init (& arena );
872875 const char * plain = "<?php\nfunction a() { return 1; }\n" ;
873876 const char * quoted = "<?php\n$s = '?>';\n/* ?> */\n$h = <<<EOT\n?>\nEOT;\n" ;
874877 const char * mixed = "<?php\nfunction a() {}\n?>\n<b>x</b>\n" ;
878+
879+ size_t before = cbm_arena_total (& arena );
875880 ASSERT (cbm_php_mask_inline_html (& arena , plain , (int )strlen (plain )) == plain );
881+ ASSERT_EQ (cbm_arena_total (& arena ), before );
882+
883+ before = cbm_arena_total (& arena );
876884 ASSERT (cbm_php_mask_inline_html (& arena , quoted , (int )strlen (quoted )) == quoted );
885+ ASSERT_EQ (cbm_arena_total (& arena ), before );
886+
887+ before = cbm_arena_total (& arena );
877888 const char * masked = cbm_php_mask_inline_html (& arena , mixed , (int )strlen (mixed ));
889+ ASSERT (cbm_arena_total (& arena ) > before );
878890 ASSERT (masked != mixed );
879891 ASSERT_EQ ((int )strlen (masked ), (int )strlen (mixed ));
880892 ASSERT_STR_EQ (masked , "<?php\nfunction a() {}\n; \n \n" );
0 commit comments