php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #32875 Repetition quantifiers
Submitted: 2005-04-28 20:52 UTC Modified: 2005-04-28 20:58 UTC
From: chiaroscuro at achromatic dot fsnet dot co dot uk Assigned:
Status: Not a bug Package: PCRE related
PHP Version: 4.3.10 OS: Apache 1.3.31
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
34 - 29 = ?
Subscribe to this entry?

 
 [2005-04-28 20:52 UTC] chiaroscuro at achromatic dot fsnet dot co dot uk
Description:
------------
I'm using quantifiers in preg_match_all functions,amongst other things, to restrict the length of strings strings submitted from HTML forms. The lower limit catches discrepant strings, but the upper limit has no effect. I've tried using very basic code, but unsuccessfully.

Reproduce code:
---------------
$failure = 0;
$userpattern = "/t{3,6}/";
$username = 'ttttttt';
$usercheck = preg_match_all($userpattern,$username,$results);
if ( !$usercheck )
{	$failure++;	}

Expected result:
----------------
$usercheck = 'tt';
This would be a disallowed string
$usercheck = 'ttttttt';
This would also be a disallowed string

Actual result:
--------------
$usercheck = 'tt'; results in $failure == 1 & the string 'fails' as it should.
$usercheck = 'ttttttt'; results in $failure = 0 & the string is allowed.
This happens however many repetitions the string comprises and with any upper limit set.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-04-28 20:58 UTC] wez@php.net
Anchor your regex using ^ and $
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 09:01:27 2024 UTC