Ticket #304 (closed Bug: worksforme)

Opened 11 months ago

Last modified 11 months ago

+ at end of allowed characters results in preg compile error

Reported by: gregmac Owned by: Geert
Priority: major Milestone: 2.1
Component: Core Version:
Keywords: Cc:

Description

Error:

preg_match() [function.preg-match]: Compilation failed: range out of order in character class at offset 18

Error occurred at line 275 of system/libraries/Router.php.
Stack Trace

    * system/libraries/Router.php [275]:

      preg_match( |^[a-z 0-9~%\.\:_-\+]+$|iu, media )

Working router.php:

$config['_allowed'] = 'a-z 0-9~%.:_+-';

Non working:

$config['_allowed'] = 'a-z 0-9~%.:_-+';

Change History

Changed 11 months ago by Geert

  • owner set to Geert

Not much I can do about this one. The Router inserts the _allowed character list in a regex character class and the dash happens to be the metacharacter to define range. Escaping it would cause the "a-z" and "0-9" parts to break.

The 'solution' is to make sure the dash cannot define a range when it shouldn't. So don't place it in between anything. As a precaution I will put the literal dash character in front of the list. This is quite general practice when allowing for dashes inside a charachter class. Also it should cause less problems when people add new characters at the end of the _allowed list.

Changed 11 months ago by Geert

  • status changed from new to closed
  • resolution set to worksforme

Fixed in r1678.

Note: See TracTickets for help on using tickets.