Page MenuHomePhabricator

Use "\z" instead of "$" to anchor validating regular expressions
ClosedPublic

Authored by epriestley on Mar 13 2014, 2:18 PM.
Tags
None
Referenced Files
F19803097: D8516.id20205.diff
Sun, Mar 1, 8:55 PM
F19796296: D8516.id20207.diff
Fri, Feb 27, 2:20 PM
F19792665: D8516.diff
Thu, Feb 26, 1:54 PM
F19593913: D8516.id.diff
Feb 2 2026, 4:46 PM
F19509962: D8516.diff
Jan 11 2026, 3:30 AM
F19506397: D8516.id20207.diff
Jan 9 2026, 4:45 PM
F19103501: D8516.id.diff
Dec 5 2025, 10:47 AM
F19007822: D8516.id20210.diff
Nov 21 2025, 8:38 PM
Subscribers

Details

Summary

Via HackerOne. In regular expressions, "$" matches "end of input, or before terminating newline". This means that the expression /^A$/ matches two strings: "A", and "A\n".

When we care about this, use \z instead, which matches "end of input" only.

This allowed registration of "username\n" and similar.

Test Plan
  • Grepped codebase for all calls to preg_match() / preg_match_all().
  • Fixed the ones where this seemed like it could have an impact.
  • Added and executed unit tests.

Diff Detail

Repository
rP Phabricator
Branch
anchor
Lint
Lint Passed
Unit
Tests Passed

Event Timeline

epriestley retitled this revision from to Use "\z" instead of "$" to anchor validating regular expressions.
epriestley updated this object.
epriestley edited the test plan for this revision. (Show Details)
epriestley added a reviewer: btrahan.
btrahan edited edge metadata.
This revision is now accepted and ready to land.Mar 13 2014, 5:38 PM
epriestley updated this revision to Diff 20210.

Closed by commit rP969d0c3e8de2 (authored by @epriestley).