Skip to content

Commit

Permalink
Fix empty children for <time>
Browse files Browse the repository at this point in the history
  • Loading branch information
xemlock committed May 6, 2019
1 parent 82172a7 commit 4b2108c
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 4 deletions.
6 changes: 3 additions & 3 deletions library/HTMLPurifier/AttrDef/HTML5/Datetime.php
Expand Up @@ -67,16 +67,16 @@ class HTMLPurifier_AttrDef_HTML5_Datetime extends HTMLPurifier_AttrDef
protected $allowedFormats = array();

/**
* @noinspection PhpDocMissingThrowsInspection
* @param array $allowedFormats OPTIONAL
* @throws HTMLPurifier_Exception If an invalid format is provided
*/
public function __construct(array $allowedFormats = array())
{
// Validate allowed formats
$allowedFormatsLookup = array();
foreach ($allowedFormats as $format) {
if (!isset(self::$formats[$format])) {
throw new InvalidArgumentException("'$format' is not a valid format");
throw new HTMLPurifier_Exception("'$format' is not a valid format");
}
$allowedFormatsLookup[$format] = true;
}
Expand Down Expand Up @@ -352,9 +352,9 @@ protected function formatTimezoneOffset(array $data)
}

/**
* @noinspection PhpDocMissingThrowsInspection
* @param string $formats
* @return HTMLPurifier_AttrDef_HTML5_Datetime
* @throws HTMLPurifier_Exception If an invalid format is provided
*/
public function make($formats)
{
Expand Down
2 changes: 2 additions & 0 deletions library/HTMLPurifier/ChildDef/HTML5/Time.php
Expand Up @@ -10,6 +10,8 @@
*/
class HTMLPurifier_ChildDef_HTML5_Time extends HTMLPurifier_ChildDef_HTML5
{
public $type = 'time';

public $excludes = array(
'time' => true,
);
Expand Down
1 change: 1 addition & 0 deletions library/HTMLPurifier/HTMLModule/HTML5/Text.php
Expand Up @@ -13,6 +13,7 @@ class HTMLPurifier_HTMLModule_HTML5_Text extends HTMLPurifier_HTMLModule_Text

/**
* @param HTMLPurifier_Config $config
* @throws HTMLPurifier_Exception
*/
public function setup($config)
{
Expand Down
5 changes: 4 additions & 1 deletion tests/HTMLPurifier/AttrDef/HTML5/DatetimeTest.php
@@ -1,5 +1,8 @@
<?php

/** @noinspection PhpDocMissingThrowsInspection */
/** @noinspection PhpUnhandledExceptionInspection */

/**
* @property HTMLPurifier_AttrDef_HTML5_Datetime $attr
*/
Expand Down Expand Up @@ -487,7 +490,7 @@ public function testMake()
}

/**
* @expectedException InvalidArgumentException
* @expectedException HTMLPurifier_Exception
* @expectedExceptionMessage not a valid format
*/
public function testInvalidFormat()
Expand Down
7 changes: 7 additions & 0 deletions tests/HTMLPurifier/HTMLModule/HTML5/TextTest.php
Expand Up @@ -221,10 +221,17 @@ public function timeDatetimeData()
array('<time datetime="PT4H18M3S">Foo</time>'),
array('<time datetime="4h 18m 3s">Foo</time>'),

// time with inline elements
array('<time datetime="Z"><i>UTC</i></time>'),

// invalid datetime - use UNIX epoch instead of removing <time> element
array('<time></time>', '<time datetime="1970-01-01"></time>'),
array('<time datetime=""></time>', '<time datetime="1970-01-01"></time>'),
array('<time datetime="">Foo</time>', '<time datetime="1970-01-01">Foo</time>'),
array('<time datetime="10">Foo</time>', '<time datetime="1970-01-01">Foo</time>'),
array('<time datetime="Foo">Foo</time>', '<time datetime="1970-01-01">Foo</time>'),
array('<time><i>Foo</i></time>', '<time datetime="1970-01-01"><i>Foo</i></time>'),
array('<time><time>Foo</time></time>', '<time datetime="1970-01-01">Foo</time>'),
);
}
}

0 comments on commit 4b2108c

Please sign in to comment.