Problem/Motivation

The title of page with HTML tags shows HTML tags in shortcut label in the shortcut toolbar tray.

Proposed resolution

Strip the html from the page title.

Remaining tasks

RTBC

Before

After

User interface changes

Fix the display message and label in the shortcut toolbar tray.

API changes

None

Data model changes

None

Original report by @malavya

When a title have HTML tags in it and the title is added in the shortcut menu, the shortcut label also prints out the HTML tags.
Shortcut bug

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

malavya created an issue. See original summary.

imalabya’s picture

Issue summary: View changes
imalabya’s picture

Added a patch for this issue.

imalabya’s picture

Status: Active » Needs review
imalabya’s picture

Title: Title with HTML tags mess up the shortcut link. » Strip HTML tags from shortcut link label
imalabya’s picture

Issue tags: +drupalconasia2016
Dinesh18’s picture

Status: Needs review » Needs work

I have tested the patch, but it is not giving the desired output.

jibran’s picture

Issue tags: +Needs tests

This is not a correct fix and we need some tests here.

jibran’s picture

jibran’s picture

Title: Strip HTML tags from shortcut link label » Page title HTML tags shows HTML tags in shortcut label in the shortcut toolbar tray
Version: 8.1.x-dev » 8.0.x-dev

We need to fix that in 8.0.x as well.

jibran’s picture

Title: Page title HTML tags shows HTML tags in shortcut label in the shortcut toolbar tray » Page title with HTML tags shows HTML tags in shortcut label in the shortcut toolbar tray

The last submitted patch, 9: strip_html_tags_from-2672668-9-fail.patch, failed testing.

The last submitted patch, 9: strip_html_tags_from-2672668-9-fail.patch, failed testing.

archunan’s picture

FileSize
34.57 KB

Hi Team,

I feel this is invalid request and its working as the way node title works.Since we have default styling for links on core, need to have any tag over the links/title

Node screen [d8nodescreen.png]

Let me your thought.

imalabya’s picture

FileSize
24.62 KB

Hi @archunan, I think you got the issue wrong.

In the example you have given <h2>About us</h2> is not a text wrapped inside HTML

tag but it is treated whole as a text. You can check that in the source.
source_title

The issue is if the page title have some HTML elements that should not be reflecting in the shortcut label when the shortcut is created.

imalabya’s picture

Ping

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.

msankhala’s picture

I tested patch provided in #9 strip_html_tags_from-2672668-9-pass.patch This patch is fixing this issue. I followed below steps in fresh drupal 8.2.0-dev installation.

  1. Clone drupal 8.2-x branch.
  2. Do a git pull make sure everything is up to date.
  3. Follow installation process.
  4. Goto main menu edit url /admin/structure/menu/manage/main where title is dynamic.
  5. Add this page into shortcut this will show you shortcut with html.
    shortcut with html
  6. Apply this patch.
  7. Drush rebuild cache with drush cr
  8. Goto same page and remove shortcut and add shortcut again.
  9. Shortcut with html is gone now. Only shortcut title is show as expected.
    shortcut without html
jibran’s picture

msankhala’s picture

Version: 8.1.x-dev » 8.2.x-dev
Status: Needs review » Reviewed & tested by the community

Yes, Moving this to RTBC, I can confirm that this patch fix this issue. Feel free to move back in "Need Review" if someone still find any issue with this.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 9: strip_html_tags_from-2672668-9-pass.patch, failed testing.

jibran’s picture

Version: 8.2.x-dev » 8.1.x-dev
Status: Needs work » Reviewed & tested by the community

This is a bug report so it should be filed against 8.1.x. Test fails seem unrelated so retesting and setting it back to RTBC.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 9: strip_html_tags_from-2672668-9-pass.patch, failed testing.

jibran’s picture

Status: Needs work » Needs review
FileSize
2.2 KB
jibran’s picture

Status: Needs review » Reviewed & tested by the community

#24 is just a reroll so back to RTBC.

Wim Leers’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/modules/shortcut/shortcut.module
    @@ -311,7 +311,8 @@ function shortcut_preprocess_page_title(&$variables) {
    +    // Strip the html tags from the title.
    

    Nit: s/the html/HTML/

  2. +++ b/core/modules/shortcut/src/Tests/ShortcutLinksTest.php
    @@ -185,6 +187,23 @@ public function testShortcutQuickLink() {
    +    // Update router to reflect newly installed module.
    +    \Drupal::service('router.builder')->rebuild();
    

    This should not be necessary?

  3. +++ b/core/modules/shortcut/src/Tests/ShortcutLinksTest.php
    @@ -185,6 +187,23 @@ public function testShortcutQuickLink() {
    +    // Test page with html tags in title.
    

    Nit: s/html/HTML/

  4. +++ b/core/modules/shortcut/src/Tests/ShortcutLinksTest.php
    @@ -185,6 +187,23 @@ public function testShortcutQuickLink() {
    +    // Add Shortcut for block content type edit form.
    

    IMO clearer:

    // Add shortcut to this page.
    
  5. +++ b/core/modules/shortcut/src/Tests/ShortcutLinksTest.php
    @@ -185,6 +187,23 @@ public function testShortcutQuickLink() {
    +    $this->assertRaw(new FormattableMarkup('Added a shortcut for %title.', ['%title' => trim(strip_tags($page_title))]));
    +
       }
    

    Nit: extraneous newline.

jibran’s picture

Wim Leers’s picture

Status: Needs review » Reviewed & tested by the community

Much better!

willzyx’s picture

Looks like very similar to #2478907: Shortcuts names for node view routes are not properly sanitized (using quick link). If you want prefer this issue and mark #2478907: Shortcuts names for node view routes are not properly sanitized (using quick link) as duplicated can we add the test coverage produced in that issue?

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 27: page_title_with_html-2672668-1.patch, failed testing.

jibran’s picture

Status: Needs work » Reviewed & tested by the community

Random fail.

catch’s picture

Status: Reviewed & tested by the community » Needs work

iCNW for #29 - please also mark the other issue duplicate and we'll transfer commit credits from their prior to commit.

jibran’s picture

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.

tstoeckler’s picture

Status: Needs review » Reviewed & tested by the community

Yup, looks good to me.

tstoeckler’s picture

Issue tags: +Dublin2016

alexpott’s picture

Adding credit from the other issue.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed d963647 to 8.3.x and 3c355f8 to 8.2.x. Thanks!

  • alexpott committed d963647 on 8.3.x
    Issue #2672668 by jibran, malavya, msankhala, archunan, Wim Leers,...

  • alexpott committed 3c355f8 on 8.2.x
    Issue #2672668 by jibran, malavya, msankhala, archunan, Wim Leers,...

Status: Fixed » Closed (fixed)

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