Skip to content

feat: htmlspecialchars/htmlentities ENT_* flags + ENT_* constants#461

Open
chadmandoo wants to merge 1 commit into
illegalstudio:mainfrom
chadmandoo:upstream-pr/htmlspecialchars-ent-flags
Open

feat: htmlspecialchars/htmlentities ENT_* flags + ENT_* constants#461
chadmandoo wants to merge 1 commit into
illegalstudio:mainfrom
chadmandoo:upstream-pr/htmlspecialchars-ent-flags

Conversation

@chadmandoo

Copy link
Copy Markdown
Contributor

What

Adds the ENT_* flag constants and extends htmlspecialchars() / htmlentities() to accept the optional flags + encoding arguments, so the common htmlspecialchars($s, ENT_QUOTES) form compiles (previously: "Undefined constant: ENT_QUOTES" + single-arg only).

How

  • Registers ENT_QUOTES(3), ENT_COMPAT, ENT_NOQUOTES, ENT_HTML401, ENT_HTML5(48), ENT_XHTML, ENT_XML1, ENT_SUBSTITUTE, ENT_IGNORE in the checker constant map (driver/init.rs) and the codegen prescan value table (prescan.rs).
  • Extends both builtin! registrations to params: [string, flags: Int = 11, encoding: Str = "UTF-8"] (PHP's default flag set).
  • An arity-tolerant lower_html_escape uses the subject (operand 0) and reuses __rt_htmlspecialchars.

Note

__rt_htmlspecialchars implements ENT_QUOTES behaviour, which matches PHP's default and the ENT_QUOTES call form (byte-parity verified: < " ' &). The flags are accepted but not yet distinguished — a flag-aware runtime (ENT_HTML5 ' vs ', ENT_NOQUOTES) is a follow-up. Builds standalone on main.

Adds the ENT_* flag constants (ENT_QUOTES=3, ENT_COMPAT, ENT_NOQUOTES, ENT_HTML401,
ENT_HTML5=48, ENT_XHTML, ENT_XML1, ENT_SUBSTITUTE, ENT_IGNORE) to the checker
constant map + the codegen prescan value table, and extends htmlspecialchars() and
htmlentities() to accept the optional flags + encoding arguments (so the common
`htmlspecialchars($s, ENT_QUOTES)` form compiles). The arity-tolerant lower_html_escape
uses the subject (operand 0) and reuses __rt_htmlspecialchars, which implements ENT_QUOTES
behaviour — matching PHP's default flag set and the ENT_QUOTES call form (byte-parity verified).
A flag-aware runtime (ENT_HTML5 ' vs &illegalstudio#39;) is a documented follow-up.

(cherry picked from commit 7e44adb)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant