Skip to content

Commit

Permalink
Add inputmode global attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
xemlock committed Aug 16, 2020
1 parent c96bc62 commit 8c7b0d9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
6 changes: 6 additions & 0 deletions library/HTMLPurifier/HTMLModule/HTML5/CommonAttributes.php
Expand Up @@ -18,6 +18,12 @@ class HTMLPurifier_HTMLModule_HTML5_CommonAttributes extends HTMLPurifier_HTMLMo
'title' => 'Text',
// tabindex attribute is supported on all elements (global attributes)
'tabindex' => 'Integer',
// Final spec for inputmode global attribute has been published on 15 Dec 2017
// https://web.archive.org/web/20171215142138/https://html.spec.whatwg.org/#input-modalities:-the-inputmode-attribute
// The 'none' value has been intentionally omitted from the list of
// allowed values, as it effectively makes the element non-editable,
// unless there is a script implementing a custom virtual keyboard.
'inputmode' => 'Enum#text,decimal,numeric,tel,search,email,url',
),
'Lang' => array(
'lang' => 'LanguageCode',
Expand Down
24 changes: 24 additions & 0 deletions tests/HTMLPurifier/HTMLModule/HTML5/CommonAttributesTest.php
Expand Up @@ -37,4 +37,28 @@ public function testTabindex()
$this->config->set('HTML.Trusted', true);
$this->assertPurification('<button tabindex="1">Foo</button>');
}

public function testInputmode()
{
$this->config->autoFinalize = false;

$this->assertPurification('<div inputmode="text">Foo</div>');
$this->assertPurification('<span inputmode="search">Foo</span>');
$this->assertPurification('<p inputmode="decimal">123</p>');
$this->assertPurification('<section inputmode="numeric">123</section>');
$this->assertPurification('<h1 inputmode="email">foo@example.com</h1>');
$this->assertPurification('<main inputmode="url">http://www.example.com</main>');
$this->assertPurification('<hr inputmode="text">');

$this->assertPurification('<div inputmode="none">Foo</div>', '<div>Foo</div>');
$this->assertPurification('<div inputmode="foo">foo</div>', '<div>foo</div>');

$this->config->set('HTML.Trusted', true);
$this->assertPurification('<input type="text" inputmode="text" value="foo">');
$this->assertPurification('<button inputmode="search">foo</button>');
$this->assertPurification('<textarea inputmode="decimal" cols="10" rows="2">123</textarea>');

$this->assertPurification('<input type="text" inputmode="none" value="foo">', '<input type="text" value="foo">');
$this->assertPurification('<input type="text" inputmode="foo" value="foo">', '<input type="text" value="foo">');
}
}

0 comments on commit 8c7b0d9

Please sign in to comment.