From fbc006e2b2b6cbe0e2ccd846ac18837a64082081 Mon Sep 17 00:00:00 2001
From: Bernhard Reiter <Bernhard Reiter@git.wordpress.org>
Date: Tue, 4 Apr 2023 10:06:27 +0000
Subject: [PATCH] HTML API: Add `has_self_closing_flag()` to Tag Processor.

In this patch we're adding `has_self_closing_flag()` to the HTML Tag Processor.
This exposes whether a currently-matched tag contains the self-closing flag `/`.

This information is critical for the evolution of the HTML API in order
to track and parse HTML structure, specifically, knowing whether an
HTML foreign element is self-closing or not.

Props dmsnell, zieladam.
Fixes #58009.
Built from https://develop.svn.wordpress.org/trunk@55619


git-svn-id: http://core.svn.wordpress.org/trunk@55131 1a063a9b-81f0-0310-95a4-ce76da25c4cd
---
 .../html-api/class-wp-html-tag-processor.php  | 25 +++++++++++++++++++
 wp-includes/version.php                       |  2 +-
 2 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/wp-includes/html-api/class-wp-html-tag-processor.php b/wp-includes/html-api/class-wp-html-tag-processor.php
index f540aa743d8f..ab0b88693ab2 100644
--- a/wp-includes/html-api/class-wp-html-tag-processor.php
+++ b/wp-includes/html-api/class-wp-html-tag-processor.php
@@ -1759,6 +1759,31 @@ public function get_tag() {
 		return strtoupper( $tag_name );
 	}
 
+	/**
+	 * Indicates if the currently matched tag contains the self-closing flag.
+	 *
+	 * No HTML elements ought to have the self-closing flag and for those, the self-closing
+	 * flag will be ignored. For void elements this is benign because they "self close"
+	 * automatically. For non-void HTML elements though problems will appear if someone
+	 * intends to use a self-closing element in place of that element with an empty body.
+	 * For HTML foreign elements and custom elements the self-closing flag determines if
+	 * they self-close or not.
+	 *
+	 * This function does not determine if a tag is self-closing,
+	 * but only if the self-closing flag is present in the syntax.
+	 *
+	 * @since 6.3.0
+	 *
+	 * @return bool Whether the currently matched tag contains the self-closing flag.
+	 */
+	public function has_self_closing_flag() {
+		if ( ! $this->tag_name_starts_at ) {
+			return false;
+		}
+
+		return '/' === $this->html[ $this->tag_ends_at - 1 ];
+	}
+
 	/**
 	 * Indicates if the current tag token is a tag closer.
 	 *
diff --git a/wp-includes/version.php b/wp-includes/version.php
index 37535097e4ba..280590de1cdd 100644
--- a/wp-includes/version.php
+++ b/wp-includes/version.php
@@ -16,7 +16,7 @@
  *
  * @global string $wp_version
  */
-$wp_version = '6.3-alpha-55618';
+$wp_version = '6.3-alpha-55619';
 
 /**
  * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.