Uploaded image for project: 'phpBB3'
  1. phpBB3
  2. PHPBB3-14552

Regex for {URL} can't handle two "#" (or parenthesis if used inside another BBCode with {TEXT})

    XMLWordPrintable

Details

    • Bug
    • Status: Open (View Workflow)
    • Major
    • Resolution: Unresolved
    • 3.1.8
    • None
    • BBCode Engine
    • None
    • PHP Version 5.5.9-1ubuntu4.14, MySQL 5.7.11, Chrome 49.0.2623.87

    Description

      Tags that use a {URL} replace with URLs containing parenthesis can not be nested in a tag that uses a {TEXT} replace.

      Steps to reproduce:

      Install latest phpbb (3.1.8)

      In ACP go to Posting / BBCodes

      Add a new BBCode

      BBCode usage: [center]{TEXT}[/center]
      HTML replacement: <div style="text-align: center">{TEXT}</div>

      Add another new BBCode

      BBCode usage: [picture]{URL}[/picture]
      HTML replacement: <img src="{URL}">

      Order that BBCodes are added matters. I'm just using "center" and "picture" to demonstrate the problems with {TEXT} and {URL} replace. I am just using these tags as examples.

      Go to the forum and try to make posts (preview is ok instead of posting).

      Shows a picture, as expected (just a URL):

      [picture]https://www.phpbb.com/assets/images/images/logo_phpbb.png?q=v[/picture]

      Shows a picture, as expected (this one has parenthesis):

      [picture]https://www.phpbb.com/assets/images/images/logo_phpbb.png?q=(v)[/picture]

      Picture code doesn't convert (two hash symbols):

      [picture]https://www.phpbb.com/assets/images/images/logo_phpbb.png#hash#tag[/picture]

      The picture will be visible and centered, as expected (just a URL):

      [center][picture]https://www.phpbb.com/assets/images/images/logo_phpbb.png?q=v[/picture][/center]

      The picture code doesn't get converted, but the center tag works (parenthesis):

      [center][picture]https://www.phpbb.com/assets/images/images/logo_phpbb.png?q=(v)[/picture][/center]

      Neither picture is converted, but the text is centered (two pictures with parenthesis inside a center):

      [center][picture]https://www.phpbb.com/assets/images/images/logo_phpbb.png?q=(v)[/picture][picture]https://www.phpbb.com/assets/images/images/logo_phpbb.png?q=(v)[/picture][/center]

      This one is particularly bad (second picture has parenthesis in URL, enclosed in center):

      [center][picture]https://www.phpbb.com/assets/images/images/logo_phpbb.png?q=v[/picture][picture]https://www.phpbb.com/assets/images/images/logo_phpbb.png?q=(v)[/picture][/center]

      This last one gives an error message: "Your message contains too few characters.", and the post text completely disappears. Very annoying if you were working on a very long post.

      When the [center] code is converted, the {TEXT} inside the [center] code is changed so that "(" becomes "&#40;" and ")" becomes "&#41;".

      So there seems to be two separate problems here. One is that {URL} won't match if there are two hash symbols. As far as I could tell two hash symbols aren't invalid in a URL. The second problem is that {TEXT} is changing parenthesis for whatever reason, and the escaping of the parenthesis contains a hash symbol, and since parenthesis tend to come in pairs you end up with two hash symbols in the URL which breaks the matching.

      Regex101.com warns of Catastrophic Backtracking when debugging {URL} matching when there are two hash symbols. Some sort of infinite loop happens with the matching and it gives up, which in PHP I suspect is causing $this->message to be set to false somewhere around message_parser.php:86, leading to the "too few characters" error message.

      Attachments

        Activity

          People

            Unassigned Unassigned
            dm-sean-knight dm-sean-knight [X] (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: