In a vanilla drupal 7.56 or 7.x-dev I create a basic page with a title and the following content where I also select Full HTML:
<svg height="333" width="333" xmlns="http://www.w3.org/2000/svg"><line style="stroke:rgb(255,0,0);stroke-width:3" x1="0" x2="333" y1="0" y2="333"></line></svg>
The front end rendering of this is broken because a <br /> is inserted just before <line:
<svg height="333" width="333" xmlns="http://www.w3.org/2000/svg"><br /><line style="stroke:rgb(255,0,0);stroke-width:3" x1="0" x2="333" y1="0" y2="333"></line></svg>
This is caused by Convert line breaks into HTML (i.e. <br> and <p>) (default checked) in admin/config/content/formats/full_html.
The code that does this is in filter.module around 1750:
$chunk = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $chunk); // make line breaks
In order to get this to work I now have to deselect the "Convert line breaks into HTML". Note that in my content there aren't any line breaks. The whole content is just an one-liner.
| Comment | File | Size | Author |
|---|---|---|---|
| #13 | 2925487-13.patch | 1.59 KB | poker10 |
| #13 | 2925487-13_test-only.patch | 778 bytes | poker10 |
| #7 | Issue-2925487-Do-not-process-svg-tags-in-filter-module.patch | 848 bytes | karivolas |
Comments
Comment #2
ioannis.cherouvim commentedComment #3
ioannis.cherouvim commentedComment #4
ioannis.cherouvim commentedComment #5
ioannis.cherouvim commentedComment #6
ioannis.cherouvim commentedComment #7
karivolas commentedThe
<svg>tag is not considered a block tag, so the filter module will add a\nat the end, which will then be replaced by a<br />.The
svgtag should be added in the firstpreg_splitat line 1707, where we set a list of tags that we don't want to process.Comment #8
karivolas commentedComment #9
karivolas commentedComment #10
akz commentedI confirm that this is a valid problem and valid patch fix. Please include in next core update.
Comment #11
WebbehReviewed via #10, although some additional confirmation would help validate the status change.
Comment #12
meltoner commentedI confirm this issue and the patch fixes the problem. Please include in next core update.
Comment #13
poker10 commentedThanks for working on this! Patch #7 looks great and it is the same change as is currently in D9, see: https://git.drupalcode.org/project/drupal/-/blob/9.5.x/core/modules/filter/filter.module#L693
I have added the SVG to the current filter tests (the same is in D9), so we can demonstrate the failure.
Manual testing also confirms that the patch is working.
Comment #16
mcdruid commentedThanks everyone!