From ec4b75596e13eda792d787dcb6b00c9cd02d80f9 Mon Sep 17 00:00:00 2001 From: xjm <xjm@65776.no-reply.drupal.org> Date: Wed, 8 Feb 2017 20:03:04 -0600 Subject: [PATCH] Issue #2656278 by alexpott, miteshmap, droplet, walangitan, empesan, ejb503, manmohandream, vaidehi bapat, gadaniels72, swentel, jamesdesq, luca_cracco, malaimo29001, Wim Leers, nileema.jadhav: Convert "Limit allowed HTML tags" input field to a textarea --- .../filter/src/Plugin/Filter/FilterHtml.php | 10 +++++++--- core/modules/filter/src/Tests/FilterAdminTest.php | 6 +++--- .../filter/tests/src/Unit/FilterHtmlTest.php | 14 ++++++++++++++ 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/core/modules/filter/src/Plugin/Filter/FilterHtml.php b/core/modules/filter/src/Plugin/Filter/FilterHtml.php index 1dc3395161a2..1dc71fba01eb 100644 --- a/core/modules/filter/src/Plugin/Filter/FilterHtml.php +++ b/core/modules/filter/src/Plugin/Filter/FilterHtml.php @@ -41,12 +41,10 @@ class FilterHtml extends FilterBase { */ public function settingsForm(array $form, FormStateInterface $form_state) { $form['allowed_html'] = array( - '#type' => 'textfield', + '#type' => 'textarea', '#title' => $this->t('Allowed HTML tags'), '#default_value' => $this->settings['allowed_html'], - '#maxlength' => 2048, '#description' => $this->t('A list of HTML tags that can be used. By default only the <em>lang</em> and <em>dir</em> attributes are allowed for all HTML tags. Each HTML tag may have attributes which are treated as allowed attribute names for that HTML tag. Each attribute may allow all values, or only allow specific values. Attribute names or values may be written as a prefix and wildcard like <em>jump-*</em>. JavaScript event attributes, JavaScript URLs, and CSS are always stripped.'), - '#size' => 250, '#attached' => array( 'library' => array( 'filter/drupal.filter.filter_html.admin', @@ -70,6 +68,12 @@ public function settingsForm(array $form, FormStateInterface $form_state) { * {@inheritdoc} */ public function setConfiguration(array $configuration) { + if (isset($configuration['settings']['allowed_html'])) { + // The javascript in core/modules/filter/filter.filter_html.admin.js + // removes new lines and double spaces so, for consistency when javascript + // is disabled, remove them. + $configuration['settings']['allowed_html'] = preg_replace('/\s+/', ' ', $configuration['settings']['allowed_html']); + } parent::setConfiguration($configuration); // Force restrictions to be calculated again. $this->restrictions = NULL; diff --git a/core/modules/filter/src/Tests/FilterAdminTest.php b/core/modules/filter/src/Tests/FilterAdminTest.php index e71b57ab45c4..830cf18d7761 100644 --- a/core/modules/filter/src/Tests/FilterAdminTest.php +++ b/core/modules/filter/src/Tests/FilterAdminTest.php @@ -206,13 +206,13 @@ function testFilterAdmin() { $this->assertTrue($full_format->access('use', $this->adminUser), 'Admin user may use Full HTML.'); $this->assertFalse($full_format->access('use', $this->webUser), 'Web user may not use Full HTML.'); - // Add an additional tag. + // Add an additional tag and extra spaces and returns. $edit = array(); - $edit['filters[filter_html][settings][allowed_html]'] = '<a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <quote>'; + $edit['filters[filter_html][settings][allowed_html]'] = "<a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>\r\n<quote>"; $this->drupalPostForm('admin/config/content/formats/manage/' . $restricted, $edit, t('Save configuration')); $this->assertUrl('admin/config/content/formats'); $this->drupalGet('admin/config/content/formats/manage/' . $restricted); - $this->assertFieldByName('filters[filter_html][settings][allowed_html]', $edit['filters[filter_html][settings][allowed_html]'], 'Allowed HTML tag added.'); + $this->assertFieldByName('filters[filter_html][settings][allowed_html]', "<a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <quote>", 'Allowed HTML tag added.'); $elements = $this->xpath('//select[@name=:first]/following::select[@name=:second]', array( ':first' => 'filters[' . $first_filter . '][weight]', diff --git a/core/modules/filter/tests/src/Unit/FilterHtmlTest.php b/core/modules/filter/tests/src/Unit/FilterHtmlTest.php index a3cde04e96d0..664c2a3001af 100644 --- a/core/modules/filter/tests/src/Unit/FilterHtmlTest.php +++ b/core/modules/filter/tests/src/Unit/FilterHtmlTest.php @@ -79,4 +79,18 @@ public function providerFilterAttributes() { ]; } + /** + * @covers ::setConfiguration + */ + public function testSetConfiguration() { + $configuration['settings'] = [ + // New lines and spaces are replaced with a single space. + 'allowed_html' => "<a> <br>\r\n <p>", + 'filter_html_help' => 1, + 'filter_html_nofollow' => 0, + ]; + $filter = new FilterHtml($configuration, 'filter_html', ['provider' => 'test']); + $this->assertSame('<a> <br> <p>', $filter->getConfiguration()['settings']['allowed_html']); + } + } -- GitLab