Skip to content
Snippets Groups Projects

Issue #3239472: preg_split in _filter_url breaks for long html tags

Open Stefanos Petrakis requested to merge issue/drupal-3239472:3239472-reroll-101x into 10.1.x

Merge request reports

Members who can merge are allowed to add commits.
Ready to merge by members who can write to the target branch.
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • added 1 commit

    • e7737b16 - Using ternary operators, added test and revised comments.

    Compare with previous version

  • Stefanos Petrakis resolved all threads

    resolved all threads

  • added 1 commit

    • 1948249c - Adding a URL to the simple HTML document to show that it is not modified.

    Compare with previous version

  • Stefanos Petrakis resolved all threads

    resolved all threads

  • 523 523 // markup, especially a '>'. Therefore, remove all comment contents and add
    524 524 // them back later.
    525 525 _filter_url_escape_comments('', TRUE);
    526 $text = preg_replace_callback('`<!--(.*?)-->`s', '_filter_url_escape_comments', $text);
    526 // Default to the current text in case preg_replace_callback fails.
    527 $text = preg_replace_callback('`<!--(.*?)-->`s', '_filter_url_escape_comments', $text) ?: $text;
    • Comment on lines +526 to +527

      I don't think this is correct. If we fail here we don't want to pass the original text to the next regular expression. That's why I went for the saved text approach. Once we refactor this into the filter plugin we can do this a much more sensible way.

    • Ok, I see that now. Here is a relevant thought though; shouldn't we break out of the loop once the preg_replace_callback on this line fails? If it does, then $text is set to NULL and the rest of the iterations are consequently not going to deliver anything?

    • image

      And do we care about such deprecation notices?

    • Stefanos Petrakis changed this line in version 6 of the diff

      changed this line in version 6 of the diff

    • Ok, so this came up and produced an error (after I removed my fix earlier). I produced a newer version that tries to tackle the deprecation notice, based on the following:

      image

      So, the new code looks like this (8b3c882a)

      -    $text = preg_replace_callback('`<!--(.*?)-->`s', '_filter_url_escape_comments', $text);
      +    $text = is_null($text) ? '' : preg_replace_callback('`<!--(.*?)-->`s', '_filter_url_escape_comments', $text);
       
           // Split at all tags; ensures that no tags or attributes are processed.
      -    $chunks = $text ? preg_split('/(<.+?>)/is', $text, -1, PREG_SPLIT_DELIM_CAPTURE) : FALSE;
      +    $chunks = is_null($text) ? [''] : preg_split('/(<.+?>)/is', $text, -1, PREG_SPLIT_DELIM_CAPTURE);

      Your thoughts @alexpott, @benji, @larowlan and anyone else that's got eyes on this one?

      Edited by Stefanos Petrakis
    • See Comments #56, #57 on the issue.

    • Please register or sign in to reply
  • added 1 commit

    • ed2fc8ee - Using the saved_text approach

    Compare with previous version

  • added 1 commit

    Compare with previous version

  • added 1 commit

    • c47b6647 - Avoid passing NULL text to preg_* functions.

    Compare with previous version

  • added 6 commits

    Compare with previous version

  • Lee Rowlands
  • Just left some comments for readability/complexity

  • Stefanos Petrakis added 257 commits

    added 257 commits

    • 1c803683...15744364 - 249 commits from branch project:10.1.x
    • e406a85d - Reroll against 10.1.x
    • 0701b3f4 - Following review
    • 86ec96a7 - Whitespace fix
    • 74098255 - Using ternary operators, added test and revised comments.
    • 2585b2d2 - Adding a URL to the simple HTML document to show that it is not modified.
    • f5e951cc - Using the saved_text approach
    • d8156cdc - Spellcheck fix
    • 72cd2c12 - Avoid passing NULL text to preg_* functions.

    Compare with previous version

  • Stefanos Petrakis resolved all threads

    resolved all threads

  • added 1 commit

    • 1a89a14e - Reverting to previous version; this can be discussed and updated if needed in [#3325466]

    Compare with previous version

  • added 1 commit

    • 1272c7aa - Removing whitespace found at end of line

    Compare with previous version

  • added 1 commit

    Compare with previous version

  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Please register or sign in to reply
    Loading