Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Warning: preg_split(): Compilation failed: POSIX collating elements are not supported at offset 1138 in Markdown.php on line 1840 #56

Closed
websafe opened this Issue Jan 21, 2013 · 5 comments

Comments

Projects
None yet
2 participants

websafe commented Jan 21, 2013

Hello.

First of all, thank You for this great Markdown implementation and keep up the good work!

I was having fun with php-markdown for the last few weeks and noticed the following. On some machines MarkdownExtra is not working. I have tried to figure out what is wrong, and I think I've found the problem.

I'm checking against branch lib commit 03fe190.

Problem

MarkdownExtra is not working on some newer machines. When error reporting is enabled MarkdownExtra may produce following warnings:

Warning: preg_split(): Compilation failed: POSIX collating elements are not supported at offset 1138 in /tmp/phpmarkdowntest/php-markdown/michelf/Markdown.php on line 1840
Warning: preg_replace_callback(): Compilation failed: POSIX collating elements are not supported at offset 115 in /tmp/phpmarkdowntest/php-markdown/michelf/Markdown.php on line 2502
Warning: preg_replace_callback(): Compilation failed: POSIX collating elements are not supported at offset 115 in /tmp/phpmarkdowntest/php-markdown/michelf/Markdown.php on line 2502

Steps to reproduce

git clone https://github.com/michelf/php-markdown.git
cd php-markdown

Now create test.php containing:

require 'michelf/Markdown.php';
require 'michelf/MarkdownExtra.php';
use michelf\MarkdownExtra;
error_reporting(E_ALL);
ini_set('display_errors', 'On');
$mp = new MarkdownExtra();
echo $mp->transform("hello world!\n============\n\nblah blah\n");

and run:

php test.php

Expected result:

<h1>hello world!</h1>

<p>blah blah</p>

Result on some machines:

Warning: preg_split(): Compilation failed: POSIX collating elements are not supported at offset 1138 in /tmp/phpmarkdowntest/php-markdown/michelf/Markdown.php on line 1840

Warning: preg_replace_callback(): Compilation failed: POSIX collating elements are not supported at offset 115 in /tmp/phpmarkdowntest/php-markdown/michelf/Markdown.php on line 2502

Warning: preg_replace_callback(): Compilation failed: POSIX collating elements are not supported at offset 115 in /tmp/phpmarkdowntest/php-markdown/michelf/Markdown.php on line 2502

at the same time Markdown works, only MarkdownExtra has problems.

Where's the difference

Both, Markdown and MarkdownExtra work as expected with PCRE v. 8.12:

# pcretest -C

PCRE version 8.12 2011-01-15
Compiled with
  UTF-8 support
  Unicode properties support
  Newline sequence is LF
  \R matches all Unicode newlines
  Internal link size = 2
  POSIX malloc threshold = 10
  Default match limit = 10000000
  Default recursion depth limit = 10000000
  Match recursion uses stack

Both work even with very old PCRE v. 7.7:

# pcretest -C

PCRE version 7.7 2008-05-07
Compiled with
  UTF-8 support
  No Unicode properties support
  Newline sequence is LF
  \R matches all Unicode newlines
  Internal link size = 2
  POSIX malloc threshold = 10
  Default match limit = 10000000
  Default recursion depth limit = 10000000
  Match recursion uses stack

But probably with newer PCRE v. 8.13 problems with MarkdownExtra start:

# pcretest -C

PCRE version 8.13 2011-08-16
Compiled with
  UTF-8 support
  Unicode properties support
  Newline sequence is LF
  \R matches all Unicode newlines
  Internal link size = 2
  POSIX malloc threshold = 10
  Default match limit = 10000000
  Default recursion depth limit = 10000000
  Match recursion uses stack

I'm not able to use MarkdownExtra on machines with PCRE v. 8.13. Currently I'm not able to check if it works with newer (than 8.13) PCRE versions. PCRE v. 8.12 and older work fine.

I don't think the PHP version is relevant here, because I've discovered this problem on PHP v. 5.3.18 and could not reproduce this on another machine with the same PHP version but a different PCRE version. That's why I think the PCRE version is more relevant in this case.

Solution

IMVHO it's about rewriting some parts of regular expressions used by MarkdownExtra.
I googled a bit and ended up with these, maybe interesting in this case, links:

I hope this helps :-)

Owner

michelf commented Jan 21, 2013

Hum... It looks to me that every regular expression having a character class starting with [., [=, or [. should have a backslash after the opening bracket, otherwise it gets treated as one of those POSIX things.

Owner

michelf commented Jan 21, 2013

Well, I meant to write [: as the third one.

websafe commented Jan 21, 2013

I think that's the case :-) but I won't be able to dig into Your regexps because I'm working hard on another project now. Just let me know if You decide to create a branch for solving this problem and I will test it in my env and let You know.

Owner

michelf commented Jan 21, 2013

I pushed the change directly to the lib branch (and also to the extra branch), because even if it doesn't solve the issue I think it's the right thing to do to avoid future issues. Please let me know if it solves the problem for you.

websafe commented Jan 21, 2013

Excellent job Michel, thank you! Now 4e091d4 it works as expected with PCRE version 8.13.

@websafe websafe closed this Jan 21, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment