Ticket #1183 (closed defect: fixed)

Opened 10 months ago

Last modified 9 months ago

FormPopulationFilter raises warning with old PCRE versions

Reported by: MugeSo@… Owned by: david
Priority: normal Milestone: 1.0.2
Component: filter Version: 1.0.1
Severity: minor Keywords:
Cc: Patch attached: no

Description

FormPopulationFilter? raises a warning like:

PHP Warning: preg_match() [<a href='function.preg-match'>function.preg-match</a>]: Compilation failed: assertion expected after (?( at offset 34 in /path-to-agavi/filter/AgaviFormPopulationFilter.class.php on line 215

Attachments

Change History

  Changed 10 months ago by david

  • reporter changed from MugeSo to MugeSo@…

  Changed 10 months ago by david

I need some reproduce code please

  Changed 10 months ago by MugeSo <mugeso@…>

simply, the regex code used in FPF raises warning in my environment.

preg_match('/;\s*charset=(")?(?P<charset>.+?(?(-2)(?=(?<!\\\\)")|(?=[;\s])))(?(-2)")/i', '');

My environment(snippet): PHP 5.2.11 PCRE (Perl Compatible Regular Expressions) Support => enabled PCRE Library Version => 6.6 06-Feb-2006 iconv support => enabled iconv implementation => glibc iconv library version => 2.5 iconv.input_encoding => ISO-8859-1 => ISO-8859-1 iconv.internal_encoding => ISO-8859-1 => ISO-8859-1 iconv.output_encoding => ISO-8859-1 => ISO-8859-1 mbstring.detect_order => no value => no value mbstring.encoding_translation => Off => Off mbstring.func_overload => 0 => 0 mbstring.http_input => pass => pass mbstring.http_output => pass => pass mbstring.internal_encoding => no value => no value mbstring.language => neutral => neutral mbstring.strict_detection => Off => Off mbstring.substitute_character => no value => no value

  Changed 9 months ago by david

That looks like a very old PCRE version... did you build your PHP against this old version intentionally? 5.2.11 should have 7.8 or 7.9, not 6.6. I'm sure that this old version is the problem. PHP 5.2.0, which is the minimum version required by Agavi, bundled PCRE 6.7.

  Changed 9 months ago by david

Okay, so the (?(-2) for relative backreferences in conditional subpatterns was introduced in PCRE 7.2, which was bundled with PHP 5.2.4. Our current minimum version is 5.2.0, which won't support this unless it's compiled against a newer version of PCRE. I can look into an alternative approach for this that does not use conditional subpatterns, that would also solve the problem you are encountering.

  Changed 9 months ago by david

  • status changed from new to assigned

follow-up: ↓ 8   Changed 9 months ago by MugeSo <mugeso@…>

Thanks, David

In fact, I didn't build php myself but use Utter Ramblings yum repository for php.  http://www.jasonlitka.com/yum-repository/ It was built against PCRE 6.6 :(

in reply to: ↑ 7   Changed 9 months ago by Mugeso@…

I find I need to updating PCRE to utter ramblings' one. It's my fault :$

But, It seems good that my fault brought good thing :D

follow-up: ↓ 11   Changed 9 months ago by david

Can you try this line as a replacement:

if(preg_match('/;\s*charset=(")?(?P<charset>.+?(?(1)(?=(?<!\\\\)")|($|(?=[;\s]))))(?(1)")/i', $meta->getAttribute('content'), $matches)) {

and tell me if it works for you?

P.S: this also fixes a bug where the regex only ever matched strings like text/html; charset="UTF-8" but never text/html; charset=UTF-8, i.e. without quotation marks. P.P.S: it never goes into this branch for me, by the way; it seems that my newer libxml detects a charset from an HTML document even in XML parsing mode by looking at a <meta http-equiv="Content-Type" header - what is your libxml version?

  Changed 9 months ago by david

See related #1185

in reply to: ↑ 9   Changed 9 months ago by Mugeso@…

Replying to david:

Can you try this line as a replacement: {{{ if(preg_match('/;\s*charset=(")?(?P<charset>.+?(?(1)(?=(?<!\\\\)")|($|(?=[;\s]))))(?(1)")/i', $meta->getAttribute('content'), $matches)) { }}} and tell me if it works for you?

Cool! It works fine for me :)

P.P.S: it never goes into this branch for me, by the way; it seems that my newer libxml detects a charset from an HTML document even in XML parsing mode by looking at a <meta http-equiv="Content-Type" header - what is your libxml version?

the version is 2.6.26 in my environment(CentOS 5.4)

  Changed 9 months ago by david

  • severity changed from normal to minor
  • summary changed from FormPopulationFilter raises warning at line 215 to FormPopulationFilter raises warning with old PCRE versions

  Changed 9 months ago by david

  • status changed from assigned to closed
  • resolution set to fixed

(In [4354]) Fix #1183: FormPopulationFilter? raises warning with old PCRE versions

  Changed 9 months ago by david

(In [4355]) Fix #1185: HTML meta tag charset detection in AgaviFormPopulationFilter? never matches strings without quotation marks (also refs #1183)

Add/Change #1183 (FormPopulationFilter raises warning with old PCRE versions)

Author


E-mail address and user name can be saved in the Preferences.


Action
as closed
Next status will be 'reopened'
 
Note: See TracTickets for help on using tickets.