To mark language changes in body text, editors can use <span lang="nl">Nederlands</span>.
But this get rendered in invalid HTML, where we will find the attribute xml:lang twice. This will fail in validators and fail wcag2.

<p><span dir="rtl" lang="he" xml:lang="he" xml:lang="he">תוכן עניינים</span></p>

Steps to reproduce

- add basic page
- keep text format 'basic HTML'
- change wysiwyg-editor to 'source'
- add <span dir="ltr" lang="fr">vive la vie</span>
- click save and publish
- look in the source HTML (not DOM), you will find:
<span dir="ltr" lang="fr" xml:lang="fr" xml:lang="fr">vive la vie</span>

we would expect:
<span dir="ltr" lang="fr">vive la vie</span>

Background

Basic HTML is using several filters. The problematic filter is 'Restrict images to this site', in combination with 'Correct faulty and chopped off HTML'. As other combinations with 'Correct faulty and chopped off HTML' work, 'Restrict images to this site' is suspicious.

This might be related to the fact that Drupal has no html5 parser (#1333730: [Meta] PHP DOM (libxml2) misinterprets HTML5). But even for html4, this result is invalid.

Comments

hanno’s picture

Issue summary: View changes
hanno’s picture

Interesting:
1. it works correct if you create a new text format with both filters applied.
2. it also works correct if I add ckeditor to it
3. when I switch to basic html, it fails.

hanno’s picture

Tracked down to 'Restrict images to this site' in combination with 'Correct faulty and chopped off HTML'. If you enable both filters on a new text format, it will produce invalid HTML.

hanno’s picture

Title: language attribute leads to incorrect HTML » 'Restrict images to this site' leads to incorrect HTML with language attribute
Issue summary: View changes
wim leers’s picture

Status: Active » Closed (duplicate)
hanno’s picture

You're sure this is a duplicate of #2105841: Xss filter() mangles image captions and title/alt/data attributes? That issue filters colons (caused by caption filter), but In this case we have twice 'xml:lang' in the output (caused by restrict images filter).

BarisW’s picture

Status: Closed (duplicate) » Active

Agreed with Hanno, I see no direct connection to that other issue. Let's re-open for consideration.

mgifford’s picture

Issue tags: +Accessibility

This is an accessibility bug we should fix.

BarisW’s picture

Status: Active » Needs review
StatusFileSize
new587 bytes

I have no idea if my solution makes any sense, but here is a patch to get the ball rolling.
It seems that only the lang results in unwanted XML attributes. so I figured: let's simply remove it.

Status: Needs review » Needs work

The last submitted patch, 9: restrict_images_to-2346989-9.patch, failed testing.

BarisW’s picture

This patch removes the xml:lang completely. This is a bit too much. Maybe we can change the regex to only remove duplicate xml attributes?

Like here: http://stackoverflow.com/a/10655934

BarisW’s picture

Status: Needs work » Needs review
StatusFileSize
new639 bytes

Ok, so the issue seems to be that both the FilterHtmlImageSecure and the FilterHtmlCorrector filter the complete body text using Html::normalize($text).
This introduces the double xml:lang tags. Here is another approach. This might not be THE perfect fix, but it is at least way better.

Basically, there seems no need to filter the html when the content doesn't contain an image?

wim leers’s picture

AFAICT the correct fix is #1333730: [Meta] PHP DOM (libxml2) misinterprets HTML5: using the \Masterminds\HTML5 library in those filters, instead of DOMDocument. Then there's no need for these hacks.

BarisW’s picture

Thanks for the info Wim! Should I need to create another issue for the patch in #12 then?
It still seems strange that the whole bunch of text is filtered when it is not needed.

wim leers’s picture

Yes, that would be great. This is a plain and simple performance improvement :)

wim leers’s picture

Title: 'Restrict images to this site' leads to incorrect HTML with language attribute » [PP-1] 'Restrict images to this site' leads to incorrect HTML with language attribute
Status: Needs review » Postponed

Let's postpone this on #1333730: [Meta] PHP DOM (libxml2) misinterprets HTML5. I'm pretty sure we'll be able to close this once #1333730: [Meta] PHP DOM (libxml2) misinterprets HTML5 is done, but let's keep this around just to be sure.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

mgifford’s picture

Issue tags: -wcag2 +WCAG

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

wim leers’s picture

Version: 9.5.x-dev » 11.x-dev
Status: Postponed » Closed (outdated)