Comments

wim leers’s picture

Status: Active » Needs review
StatusFileSize
new1.78 KB
new2.43 KB
wim leers’s picture

StatusFileSize
new2.42 KB
new873 bytes

Forgot to clean up the comment.

sun’s picture

Status: Needs review » Needs work
  1. +++ b/core/modules/filter/filter.module
    @@ -401,7 +401,7 @@ function check_markup($text, $format_id = NULL, $langcode = '', $cache = FALSE,
    -  $filters = $format->filters();
    +  $filters = $format->filters()->sort();
    

    Unless there is a very good reason for why we cannot, filters() (FilterBag) should return the sorted filters already.

    We should prevent anyone from operating on unsorted filters.

  2. +++ b/core/modules/filter/lib/Drupal/filter/Tests/FilterAPITest.php
    @@ -68,7 +68,37 @@ function setUp() {
    +          'status' => -10,
    

    weight?

wim leers’s picture

Status: Needs work » Needs review
StatusFileSize
new1.67 KB
new2.45 KB
new968 bytes

Ughhh… I completely messed up everything just before posting the patch :(

I agree with #1 in principle, but I fear that goes against the semantics of PluginBags? Why else wouldn't that have been done in the conversion to PluginBags?

The last submitted patch, 1: filter_order-2224427-1-test_only_FAIL.patch, failed testing.

The last submitted patch, 4: filter_order-2224427-4-test_only_FAIL.patch, failed testing.

tim.plunkett’s picture

Hmm, FilterFormat::preSave() sorts the filters, I would have thought that would take care of it.

If you call $format->filters(), it gives you the bag with the filters uninitialized. That way you can check things like ->has('filter_html') quickly.
sort() always initializes all of the plugins.

But if you're about to loop over them anyway, you don't really care...

wim leers’s picture

#7: so your point is… that we should make FilterFormat::filters() always sort the filters?

tim.plunkett’s picture

StatusFileSize
new3.12 KB
new2.04 KB

They can be sorted on init and still sorted again on save, but not on every retrieval.

wim leers’s picture

StatusFileSize
new3.8 KB
new819 bytes

Thanks! :)

I'm fine with that, but then we need to update FilterFormatInterface::filters() also.

Status: Needs review » Needs work

The last submitted patch, 10: filter-2224427-10.patch, failed testing.

The last submitted patch, 9: filter-2224427-9.patch, failed testing.

tim.plunkett’s picture

Status: Needs work » Needs review
StatusFileSize
new4.22 KB
new734 bytes

Hah! That test is actually wrong. The order of the value returned by getFilterTypes does not actually matter, but in HEAD it was unsorted, and the test was asserting based on that order. Now that we're sorting them, the type of the filter with weight -10 comes before the -1 filter.

vegi’s picture

I have the exact same problem with Drupal 7.26.
Is there a fix, too?

The PHP-Evaluator should come before the "GMap Macro expander". The order is correct set in admin/config/content/formats/php_code but it doesn't work.

sun’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

Awesome - that looks much better + secure now, thanks! :-)

  • Commit e16cbbe on 8.x by webchick:
    Issue #2224427 by Wim Leers, tim.plunkett: Filter order no longer...
webchick’s picture

Status: Reviewed & tested by the community » Fixed

vegi: Hm. Doesn't sound related, since this is D8-specific code. Maybe open a separate 7.x issue to discuss?

I needed to add a comment to this prior to commit, because I had no idea what "crazy" means in this context. It doesn't feel overly crazy to me to strip out invalid HTML prior to escaping angle brackets. (I guess you meant it's crazy to say that llamas are not awesome, but then I'd call that variable "$crazy_text" instead.)

Though I'm all for silliness, in this case I think it might be an example of us being a little too silly, to the detriment of the next poor person to read/debug this code. :) Not really a reason to hold up a critical, though.

Anyway, extended the description with this:

    // Create crazy HTML format, which strips out disallowed tags prior to
    // escaping HTML.

And committed/pushed to 8.x. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.