lanthaler / JsonLD

JSON-LD processor for PHP
MIT License
336 stars 61 forks source link

Undocumented dependency for regex parsing in IRI.php? #41

Closed jneubert closed 11 years ago

jneubert commented 11 years ago

The parse() function of IRI.php works fine for me on a Centos 6/PHP 5.3.3 installation. It fails however on Centos 5 (with rpm package php53/PHP 5.3.3 installed).

I could track it down to to following lines of code (first and last line added for demonstration):

    $iri = 'http://www.w3.org/2004/02/skos/core#hiddenLabel';

    // Parse IRI by using the regular expression as specified by
    // http://tools.ietf.org/html/rfc3986#appendix-B
    $regex = '|^((?P<scheme>[^:/?#]+):)?' .
                '((?P<doubleslash>//)(?P<authority>[^/?#]*))?(?P<path>[^?#]*)' .
                '((?<querydef>\?)(?P<query>[^#]*))?(#(?P<fragment>.*))?|';
    preg_match($regex, $iri, $match);

    print $match['scheme'] . "\n";

On Centos 6, "http" is printed.

On Centos 5, I get the message:

PHP Warning: preg_match(): Compilation failed: unrecognized character after (?< at offset 89 in [...]temp.php on line 9

without any other output.

Perhaps I'm missing some unknown dependency - help much appreciated.

Cheers, Joachim

lanthaler commented 11 years ago

Thanks for reporting this Joachim. You are right, there’s a dependency on the PCRE library. Apparently CentOS’s default repositories don’t have the latest version. Can you try to update it to at least 8.0 (perhaps using http://www.jasonlitka.com/yum-repository/). You can easily check the version of the PCRE library by running

php composer.phar show --platform

I’ve already updated composer.json to specifiy this dependency. Let me know if that solves the issue.

jneubert commented 11 years ago

Thanks for the hints, Markus. Unfortunately, after setting up the utterramblings repo, I could not install the pcre-8.x version from there - presumably the active yum-plugins (security, protectbase) prevent it. Circumventing this on my dev system would not help much, because the IT team responsible for the prod system for sure would not accept such a step. Since the regex worked in a prior JsonLD version, would it perhaps be possible to re-formulate it to a pcre-6.6 compatible version?

lanthaler commented 11 years ago

I would be happy to do so but don’t have the time right now to do it myself. Could you file a PR?

osma commented 10 years ago

I have a related problem. I'm also trying to deploy on CentOS 6 and Composer now complains that lib-pcre 8.0 is not available (CentOS 6 has lib-pcre 7.9).

As I understand, you already changed the code to be compatible with older pcre, but the dependency in composer.json is specified for >= 8.0. Could you please change composer.json to match the updated code? Maybe to lib-pcre >=6.6. Then Composer would be happy and not fail to install ml/iri 1.1.3.

At the moment I'm back to using ml/iri 1.1.2 because that works on CentOS 6.

Thanks, Osma

lanthaler commented 10 years ago

Good catch. I've updated composer.json to require lib-pcre >= 4.0 (which is the version that added support for named subpatterns using the Python syntax). Could you please confirm that this resolves the problem you are experiencing.

Thanks

osma commented 10 years ago

Thanks a lot, ml/iri 1.1.4 installs and works perfectly on CentOS 6 now!