• Resolved nriley

    (@nriley)


    Hi,

    I have been using Relevanssi without problems for years (10 maybe?) Since I recently upgraded WordPress and Relevanssi I have started getting “compilation failed” error warnings. This seems to be happening in relevanssi_add_accent_variations.

    Example:

    PHP Warning:  preg_replace(): Compilation failed: missing ) at offset 57 in [...]/wp-content/plugins/relevanssi/lib/excerpts-highlights.php on line 490
    PHP Warning:  preg_replace(): Compilation failed: unmatched parentheses at offset 39 in [...]/wp-content/plugins/relevanssi/lib/excerpts-highlights.php on line 490
    

    I added some logging in excerpts-highlights.php to see what transformations are happening to the term. It looks like an initially quoted ) in the search term is getting unquoted when adding accent variations. For example, I searched for test).

    initial term: test), referer: https://[...]/?s=test
    quoted term: test\\), referer: https://[...]/?s=test
    with accent variations: t-?(e|\xc3\xa9|\xc3\xa8|\xc3\xaa|\xc3\xab)-?s-?t-?\\-?), referer: https://[...]/?s=test
    PHP Warning:  preg_replace(): Compilation failed: unmatched parentheses at offset 31 in [...]/wp-content/plugins/relevanssi/lib/excerpts-highlights.php on line 492, referer: https://[...]/?s=test
    

    Something similar happens when searching for test[.

    
    initial term: test[, referer: https://[...]/?s=test%5D
    quoted term: test\\[, referer: https://[...]/?s=test%5D
    with accent variations: t-?(e|\xc3\xa9|\xc3\xa8|\xc3\xaa|\xc3\xab)-?s-?t-?\\-?[, referer: https://[...]/?s=test%5D
    PHP Warning:  preg_replace(): Compilation failed: missing terminating ] for character class at offset 32 in [...]/wp-content/plugins/relevanssi/lib/excerpts-highlights.php on line 492, referer: https://[...]/?s=test%5D
    
    • This topic was modified 5 years, 3 months ago by nriley.
    • This topic was modified 5 years, 3 months ago by nriley.
    • This topic was modified 5 years, 3 months ago by nriley.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Mikko Saari

    (@msaari)

    Yeah, looks like parentheses and brackets are not quoted properly. This was broken in the latest release, which started using untokenized search terms for excerpts to get better excerpts.

    I’ll add this to my issue tracker and will fix this for the next version. I’ll post here when I have a fix available.

    Just curious: is there a particular reason you’re using parentheses and brackets often enough in searches that you’d notice something like this?

    Plugin Author Mikko Saari

    (@msaari)

    Thread Starter nriley

    (@nriley)

    I’m not using parentheses or brackets in my searches — they’re coming from the Internet, I suspect from something trying to exploit some bug or other. Thanks for the quick fix — will test later today when I get a chance.

    Thread Starter nriley

    (@nriley)

    Applied your commit and it looks good. Thanks!

    initial term: test)
    quoted term: test\\)
    with accent variations: t-?(e|\xc3\xa9|\xc3\xa8|\xc3\xaa|\xc3\xab)-?s-?t-?\\)
    initial term: test[
    quoted term: test\\[
    with accent variations: t-?(e|\xc3\xa9|\xc3\xa8|\xc3\xaa|\xc3\xab)-?s-?t-?\\[

    It’s not just parentheses and brackets, eg. entering *test will spew php warnings, too. In my particular case I was testing searching for a phone number (xxx) xxx-xxx and I mis-typed the first parenthesis as *xxx) xxx-xxx .. but there is a legitimate use case for a parenthesis. ??

    • This reply was modified 5 years, 3 months ago by jnorell.
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Accent variations creating invalid regular expression?’ is closed to new replies.