php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53728 Recursive Reference or Repetition Don't Works
Submitted: 2011-01-12 18:25 UTC Modified: 2011-01-12 22:55 UTC
From: i at WalkinRaven dot name Assigned:
Status: Not a bug Package: PCRE related
PHP Version: 5.3SVN-2011-01-12 (SVN) OS: Ubuntu 11.04
Private report: No CVE-ID: None
 [2011-01-12 18:25 UTC] i at WalkinRaven dot name
Description:
------------
PCRE 8.02 2010-03-19 

I use the code below to validate domain names according to RFC 1034 3.5
http://www.rfc-editor.org/rfc/rfc1034.txt

This rules is:

<domain>        ::=<subdomain>  | " "
<subdomain>     ::=<label>  |<subdomain>  "."<label>
<label>         ::=<letter>  [ [<ldh-str>  ]<let-dig>  ]
<ldh-str>       ::=<let-dig-hyp>  |<let-dig-hyp>  <ldh-str>
<let-dig-hyp>   ::=<let-dig>  | "-"
<let-dig>       ::=<letter>  |<digit>
<letter>        ::= any one of the 52 alphabetic characters A through Z in
upper case and a through z in lower case
<digit>         ::= any one of the ten digits 0 through 9 

I've checked my pattern many times, and guess there may something wrong with PCRE.

Test script:
---------------
$domain = 'www.WalkinRaven.name';

$result = \preg_match
(
  '/^
    (?P<label>
      (?P<letter>[a-z]) |                                      # One-letter domain name
      (?P>letter) (?P<let_dig>[a-z 0-9]) |                     # Two-letters domain name
      (?P>letter) (?P<ldh_str>[a-z 0-9 \-]){1,61} (?P>let_dig) # More-letters domain name
)
(\. (?P>label))*+  # More labels
\.?                # Root domain name
$/Dix',
$domain
);

echo $result;

Expected result:
----------------
1

Actual result:
--------------
0

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-01-12 22:55 UTC] felipe@php.net
-Status: Open +Status: Bogus
 [2011-01-12 22:55 UTC] felipe@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.


 [2011-01-13 05:35 UTC] i at WalkinRaven dot name
No, I think this is a bug, for if you just remove all references, like changing regular expression to:

/^
    (
      [a-z] |                                      # One-letter domain name
      [a-z] [a-z 0-9] |                     # Two-letters domain name
      [a-z] ([a-z 0-9 \-]){1,61} [a-z 0-9] # More-letters domain name
)
(\. (
      [a-z] |                                      # One-letter domain name
      [a-z] [a-z 0-9] |                     # Two-letters domain name
      [a-z] ([a-z 0-9 \-]){1,61} [a-z 0-9] # More-letters domain name
))*?  # More labels
\.?                # Root domain name
$/Dix

All others are not changed, you will get the right result.

P.S. in original I've written a mistake for "(\. (?P>label))*+  # More labels" should be "(\. (?P>label))*?  # More labels".
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 14:01:28 2024 UTC