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
F18820680: D8516.diff
Wed, Oct 22, 4:33 PM
F18783540: D8516.id20207.diff
Mon, Oct 13, 7:48 AM
F18772383: D8516.id20206.diff
Thu, Oct 9, 2:12 AM
F18758613: D8516.id20210.diff
Sun, Oct 5, 10:56 PM
F18751564: D8516.id.diff
Sat, Oct 4, 11:41 AM
F18741575: D8516.id20205.diff
Thu, Oct 2, 2:40 PM
F18737425: D8516.id.diff
Wed, Oct 1, 10:38 AM
F18725626: D8516.diff
Tue, Sep 30, 5:43 AM
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
Lint
Lint Skipped
Unit
Tests Skipped

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).