diff --git a/library/HTMLPurifier/AttrDef/CSS.php b/library/HTMLPurifier/AttrDef/CSS.php index 1a8a9e3a..6a543d2f 100644 --- a/library/HTMLPurifier/AttrDef/CSS.php +++ b/library/HTMLPurifier/AttrDef/CSS.php @@ -3,6 +3,12 @@ require_once 'HTMLPurifier/AttrDef.php'; require_once 'HTMLPurifier/CSSDefinition.php'; +/** + * Validates the HTML attribute style, otherwise known as CSS. + * @note We don't implement the whole CSS specification, so it might be + * difficult to reuse this component in the context of validating + * actual stylesheet declarations. + */ class HTMLPurifier_AttrDef_CSS extends HTMLPurifier_AttrDef { diff --git a/library/HTMLPurifier/AttrDef/CSSLength.php b/library/HTMLPurifier/AttrDef/CSSLength.php index 9bf18ba4..b279eabf 100644 --- a/library/HTMLPurifier/AttrDef/CSSLength.php +++ b/library/HTMLPurifier/AttrDef/CSSLength.php @@ -3,13 +3,29 @@ require_once 'HTMLPurifier/AttrDef.php'; require_once 'HTMLPurifier/AttrDef/Number.php'; +/** + * Represents a Length as defined by CSS. + * @warning Be sure not to confuse this with HTMLPurifier_AttrDef_Length! + */ class HTMLPurifier_AttrDef_CSSLength extends HTMLPurifier_AttrDef { + /** + * Valid unit lookup table. + * @warning The code assumes all units are two characters long. Be careful + * if we have to change this behavior! + */ var $units = array('em' => true, 'ex' => true, 'px' => true, 'in' => true, 'cm' => true, 'mm' => true, 'pt' => true, 'pc' => true); + /** + * Instance of HTMLPurifier_AttrDef_Number to defer number validation to + */ var $number_def; + /** + * @param $non_negative Bool indication whether or not negative values are + * allowed. + */ function HTMLPurifier_AttrDef_CSSLength($non_negative = false) { $this->number_def = new HTMLPurifier_AttrDef_Number($non_negative); } diff --git a/library/HTMLPurifier/AttrDef/Class.php b/library/HTMLPurifier/AttrDef/Class.php index 7e29f8ba..551eb332 100644 --- a/library/HTMLPurifier/AttrDef/Class.php +++ b/library/HTMLPurifier/AttrDef/Class.php @@ -3,6 +3,9 @@ require_once 'HTMLPurifier/AttrDef.php'; require_once 'HTMLPurifier/Config.php'; +/** + * Validates the contents of the global HTML attribute class. + */ class HTMLPurifier_AttrDef_Class extends HTMLPurifier_AttrDef { diff --git a/library/HTMLPurifier/AttrDef/Color.php b/library/HTMLPurifier/AttrDef/Color.php index c527b598..dcc4adf1 100644 --- a/library/HTMLPurifier/AttrDef/Color.php +++ b/library/HTMLPurifier/AttrDef/Color.php @@ -2,6 +2,9 @@ require_once 'HTMLPurifier/AttrDef.php'; +/** + * Validates Color as defined by CSS. + */ class HTMLPurifier_AttrDef_Color { diff --git a/library/HTMLPurifier/AttrDef/Composite.php b/library/HTMLPurifier/AttrDef/Composite.php index 39efad0a..7be0bd97 100644 --- a/library/HTMLPurifier/AttrDef/Composite.php +++ b/library/HTMLPurifier/AttrDef/Composite.php @@ -1,10 +1,26 @@ defs = $defs; } diff --git a/library/HTMLPurifier/AttrDef/Enum.php b/library/HTMLPurifier/AttrDef/Enum.php index ace1c54f..a7da54cd 100644 --- a/library/HTMLPurifier/AttrDef/Enum.php +++ b/library/HTMLPurifier/AttrDef/Enum.php @@ -3,12 +3,27 @@ require_once 'HTMLPurifier/AttrDef.php'; // Enum = Enumerated +/** + * Validates a keyword against a list of valid values. + */ class HTMLPurifier_AttrDef_Enum extends HTMLPurifier_AttrDef { + /** + * Lookup table of valid values. + */ var $valid_values = array(); + + /** + * Bool indicating whether or not enumeration is case sensitive. + * @note In general this is always case insensitive. + */ var $case_sensitive = false; // values according to W3C spec + /** + * @param $valid_values List of valid values + * @param $case_sensitive Bool indicating whether or not case sensitive + */ function HTMLPurifier_AttrDef_Enum( $valid_values = array(), $case_sensitive = false) { diff --git a/library/HTMLPurifier/AttrDef/FontFamily.php b/library/HTMLPurifier/AttrDef/FontFamily.php index bb49d6da..32da724e 100644 --- a/library/HTMLPurifier/AttrDef/FontFamily.php +++ b/library/HTMLPurifier/AttrDef/FontFamily.php @@ -4,9 +4,16 @@ require_once 'HTMLPurifier/AttrDef.php'; // whitelisting allowed fonts would be nice +/** + * Validates a font family list according to CSS spec + */ class HTMLPurifier_AttrDef_FontFamily extends HTMLPurifier_AttrDef { + /** + * Generic font family keywords. + * @protected + */ var $generic_names = array( 'serif' => true, 'sans-serif' => true, diff --git a/library/HTMLPurifier/AttrDef/Host.php b/library/HTMLPurifier/AttrDef/Host.php index 69fa6323..c373d9ef 100644 --- a/library/HTMLPurifier/AttrDef/Host.php +++ b/library/HTMLPurifier/AttrDef/Host.php @@ -4,9 +4,15 @@ require_once 'HTMLPurifier/AttrDef.php'; require_once 'HTMLPurifier/AttrDef/IPv4.php'; require_once 'HTMLPurifier/AttrDef/IPv6.php'; +/** + * Validates a host according to the IPv4, IPv6 and DNS specifications. + */ class HTMLPurifier_AttrDef_Host extends HTMLPurifier_AttrDef { + /** + * Instances of HTMLPurifier_AttrDef_IPv4 and HTMLPurifier_AttrDef_IPv6 + */ var $ipv4, $ipv6; function HTMLPurifier_AttrDef_Host() { diff --git a/library/HTMLPurifier/AttrDef/ID.php b/library/HTMLPurifier/AttrDef/ID.php index 6f110a34..da8ab091 100644 --- a/library/HTMLPurifier/AttrDef/ID.php +++ b/library/HTMLPurifier/AttrDef/ID.php @@ -2,12 +2,15 @@ require_once 'HTMLPurifier/AttrDef.php'; require_once 'HTMLPurifier/IDAccumulator.php'; - -// NOTE QUIRKY BEHAVIOR: even though this is the id processor, it -// will ignore directive Attr:IDBlacklist, since it will only -// go according to the ID accumulator. Since the accumulator is -// automatically generated, it will have already absorbed the -// blacklist. If you're hacking around, make sure you use load()! + +/** + * Validates the HTML attribute ID. + * @warning Even though this is the id processor, it + * will ignore the directive Attr:IDBlacklist, since it will only + * go according to the ID accumulator. Since the accumulator is + * automatically generated, it will have already absorbed the + * blacklist. If you're hacking around, make sure you use load()! + */ class HTMLPurifier_AttrDef_ID extends HTMLPurifier_AttrDef { diff --git a/library/HTMLPurifier/AttrDef/IPv4.php b/library/HTMLPurifier/AttrDef/IPv4.php index 1982512d..a16305ad 100644 --- a/library/HTMLPurifier/AttrDef/IPv4.php +++ b/library/HTMLPurifier/AttrDef/IPv4.php @@ -2,12 +2,17 @@ require_once 'HTMLPurifier/AttrDef.php'; -// spliced from Feyd's IPv6 function (pd) - +/** + * Validates an IPv4 address + * @author Feyd @ forums.devnetwork.net (public domain) + */ class HTMLPurifier_AttrDef_IPv4 extends HTMLPurifier_AttrDef { - // regex is public so that IPv6 can reuse it + /** + * IPv4 regex, protected so that IPv6 can reuse it + * @protected + */ var $ip4; function HTMLPurifier_AttrDef_IPv4() { diff --git a/library/HTMLPurifier/AttrDef/IPv6.php b/library/HTMLPurifier/AttrDef/IPv6.php index 70cbf79d..21b1ed8f 100644 --- a/library/HTMLPurifier/AttrDef/IPv6.php +++ b/library/HTMLPurifier/AttrDef/IPv6.php @@ -2,11 +2,12 @@ require_once 'HTMLPurifier/AttrDef/IPv4.php'; -// IPv6 by Feyd, source is in public domain - -// note that this expects the brackets to be removed from IPv6 addresses -// extends from the IPv4 impl. so we can borrow its regex - +/** + * Validates an IPv6 address. + * @author Feyd @ forums.devnetwork.net (public domain) + * @note This function requires brackets to have been removed from address + * in URI. + */ class HTMLPurifier_AttrDef_IPv6 extends HTMLPurifier_AttrDef_IPv4 { diff --git a/library/HTMLPurifier/AttrDef/Integer.php b/library/HTMLPurifier/AttrDef/Integer.php index 3c647173..71ac98c3 100644 --- a/library/HTMLPurifier/AttrDef/Integer.php +++ b/library/HTMLPurifier/AttrDef/Integer.php @@ -2,14 +2,24 @@ require_once 'HTMLPurifier/AttrDef.php'; -// appears to be a dud class: no currently allowed CSS uses this type -// Uses this: widows, orphans, z-index, counter-increment, counter-reset - +/** + * Validates an integer. + * @note While this class was modeled off the CSS definition, no currently + * allowed CSS uses this type. The properties that do are: widows, + * orphans, z-index, counter-increment, counter-reset. Some of the + * HTML attributes, however, find use for a non-negative version of this. + */ class HTMLPurifier_AttrDef_Integer extends HTMLPurifier_AttrDef { + /** + * Bool indicating whether or not integers can only be positive. + */ var $non_negative = false; + /** + * @param $non_negative bool indicating whether or not only positive + */ function HTMLPurifier_AttrDef_Integer($non_negative = false) { $this->non_negative = $non_negative; } diff --git a/library/HTMLPurifier/AttrDef/Lang.php b/library/HTMLPurifier/AttrDef/Lang.php index 3f82b730..58809c2b 100644 --- a/library/HTMLPurifier/AttrDef/Lang.php +++ b/library/HTMLPurifier/AttrDef/Lang.php @@ -2,8 +2,10 @@ require_once 'HTMLPurifier/AttrDef.php'; -// built according to RFC 3066, which obsoleted RFC 1766 - +/** + * Validates the HTML attribute lang, effectively a language code. + * @note Built according to RFC 3066, which obsoleted RFC 1766 + */ class HTMLPurifier_AttrDef_Lang extends HTMLPurifier_AttrDef { diff --git a/library/HTMLPurifier/AttrDef/MultiLength.php b/library/HTMLPurifier/AttrDef/MultiLength.php index d14ecfee..2690a2ff 100644 --- a/library/HTMLPurifier/AttrDef/MultiLength.php +++ b/library/HTMLPurifier/AttrDef/MultiLength.php @@ -3,6 +3,12 @@ require_once 'HTMLPurifier/AttrDef.php'; require_once 'HTMLPurifier/AttrDef/Length.php'; +/** + * Validates a MultiLength as defined by the HTML spec. + * + * A multilength is either a integer (pixel count), a percentage, or + * a relative number. + */ class HTMLPurifier_AttrDef_MultiLength extends HTMLPurifier_AttrDef_Length { diff --git a/library/HTMLPurifier/AttrDef/Multiple.php b/library/HTMLPurifier/AttrDef/Multiple.php index 4ffb1a66..d4555e3c 100644 --- a/library/HTMLPurifier/AttrDef/Multiple.php +++ b/library/HTMLPurifier/AttrDef/Multiple.php @@ -2,12 +2,30 @@ require_once 'HTMLPurifier/AttrDef.php'; +/** + * Framework class for strings that involve multiple values. + * + * Certain CSS properties such as border-width and margin allow multiple + * lengths to be specified. This class can take a vanilla border-width + * definition and multiply it, usually into a max of four. + */ class HTMLPurifier_AttrDef_Multiple extends HTMLPurifier_AttrDef { + /** + * Instance of component definition to defer validation to. + */ var $single; + + /** + * Max number of values allowed. + */ var $max; + /** + * @param $single HTMLPurifier_AttrDef to multiply + * @param $max Max number of values allowed (usually four) + */ function HTMLPurifier_AttrDef_Multiple($single, $max = 4) { $this->single = $single; $this->max = $max; diff --git a/library/HTMLPurifier/AttrDef/Number.php b/library/HTMLPurifier/AttrDef/Number.php index 02a80b97..f28f80fc 100644 --- a/library/HTMLPurifier/AttrDef/Number.php +++ b/library/HTMLPurifier/AttrDef/Number.php @@ -1,10 +1,19 @@ non_negative = $non_negative; } diff --git a/library/HTMLPurifier/AttrDef/NumberSpan.php b/library/HTMLPurifier/AttrDef/NumberSpan.php deleted file mode 100644 index acdfeb6b..00000000 --- a/library/HTMLPurifier/AttrDef/NumberSpan.php +++ /dev/null @@ -1,23 +0,0 @@ - \ No newline at end of file diff --git a/library/HTMLPurifier/AttrDef/Percentage.php b/library/HTMLPurifier/AttrDef/Percentage.php index 9c9ba4fe..35fb5ab0 100644 --- a/library/HTMLPurifier/AttrDef/Percentage.php +++ b/library/HTMLPurifier/AttrDef/Percentage.php @@ -3,11 +3,21 @@ require_once 'HTMLPurifier/AttrDef.php'; require_once 'HTMLPurifier/AttrDef/Number.php'; +/** + * Validates a Percentage as defined by the HTML spec. + * @note This also allows integer pixel values. + */ class HTMLPurifier_AttrDef_Percentage extends HTMLPurifier_AttrDef { + /** + * Instance of HTMLPurifier_AttrDef_Number to defer pixel validation + */ var $number_def; + /** + * @param Bool indicating whether to forbid negative values + */ function HTMLPurifier_AttrDef_Percentage($non_negative = false) { $this->number_def = new HTMLPurifier_AttrDef_Number($non_negative); } diff --git a/library/HTMLPurifier/AttrDef/Pixels.php b/library/HTMLPurifier/AttrDef/Pixels.php index 98a6e18f..d252e787 100644 --- a/library/HTMLPurifier/AttrDef/Pixels.php +++ b/library/HTMLPurifier/AttrDef/Pixels.php @@ -2,6 +2,9 @@ require_once 'HTMLPurifier/AttrDef.php'; +/** + * Validates an integer representation of pixels according to the HTML spec. + */ class HTMLPurifier_AttrDef_Pixels extends HTMLPurifier_AttrDef { diff --git a/library/HTMLPurifier/AttrDef/Text.php b/library/HTMLPurifier/AttrDef/Text.php index 4a9850df..eb2a24a7 100644 --- a/library/HTMLPurifier/AttrDef/Text.php +++ b/library/HTMLPurifier/AttrDef/Text.php @@ -2,6 +2,9 @@ require_once 'HTMLPurifier/AttrDef.php'; +/** + * Validates arbitrary text according to the HTML spec. + */ class HTMLPurifier_AttrDef_Text extends HTMLPurifier_AttrDef { diff --git a/library/HTMLPurifier/AttrDef/TextDecoration.php b/library/HTMLPurifier/AttrDef/TextDecoration.php index 83d6b5b0..90d011e4 100644 --- a/library/HTMLPurifier/AttrDef/TextDecoration.php +++ b/library/HTMLPurifier/AttrDef/TextDecoration.php @@ -2,9 +2,18 @@ require_once 'HTMLPurifier/AttrDef.php'; +/** + * Validates the value for the CSS property text-decoration + * @note This class could be generalized into a version that acts sort of + * like Enum except you can compound the allowed values. + */ class HTMLPurifier_AttrDef_TextDecoration extends HTMLPurifier_AttrDef { + /** + * Lookup table of allowed values. + * @protected + */ var $allowed_values = array( 'line-through' => true, 'overline' => true, diff --git a/library/HTMLPurifier/AttrDef/URI.php b/library/HTMLPurifier/AttrDef/URI.php index ca437f96..4a48d7b1 100644 --- a/library/HTMLPurifier/AttrDef/URI.php +++ b/library/HTMLPurifier/AttrDef/URI.php @@ -11,6 +11,10 @@ HTMLPurifier_ConfigDef::define( 'select the proper object validator when no scheme information is present.' ); +/** + * Validates a URI as defined by RFC 3986. + * @note Scheme-specific mechanics deferred to HTMLPurifier_URIScheme + */ class HTMLPurifier_AttrDef_URI extends HTMLPurifier_AttrDef { diff --git a/library/HTMLPurifier/HTMLDefinition.php b/library/HTMLPurifier/HTMLDefinition.php index ca7d3404..374eea07 100644 --- a/library/HTMLPurifier/HTMLDefinition.php +++ b/library/HTMLPurifier/HTMLDefinition.php @@ -9,7 +9,7 @@ require_once 'HTMLPurifier/AttrDef.php'; require_once 'HTMLPurifier/AttrDef/Pixels.php'; require_once 'HTMLPurifier/AttrDef/Length.php'; require_once 'HTMLPurifier/AttrDef/MultiLength.php'; - require_once 'HTMLPurifier/AttrDef/NumberSpan.php'; + require_once 'HTMLPurifier/AttrDef/Integer.php'; require_once 'HTMLPurifier/AttrDef/URI.php'; require_once 'HTMLPurifier/AttrDef/CSS.php'; require_once 'HTMLPurifier/AttrTransform.php'; @@ -331,7 +331,7 @@ class HTMLPurifier_HTMLDefinition $this->info['col']->attr['width'] = $this->info['colgroup']->attr['width'] = $e_MultiLength; - $e__NumberSpan = new HTMLPurifier_AttrDef_NumberSpan(); + $e__NumberSpan = new HTMLPurifier_AttrDef_Integer(true); $this->info['colgroup']->attr['span'] = $this->info['col']->attr['span'] = $this->info['td']->attr['rowspan'] = diff --git a/tests/HTMLPurifier/AttrDef/NumberSpanTest.php b/tests/HTMLPurifier/AttrDef/NumberSpanTest.php deleted file mode 100644 index bb9c3050..00000000 --- a/tests/HTMLPurifier/AttrDef/NumberSpanTest.php +++ /dev/null @@ -1,28 +0,0 @@ -def = new HTMLPurifier_AttrDef_NumberSpan(); - - // this one requires a little explanation. A colspan="1" shouldn't - // exist at all: it's just a dud, since the default value is already - // supplied - $this->assertDef('1', false); - - $this->assertDef('4'); - $this->assertDef('4.5', '4'); // round down (truncate) - $this->assertDef('0', false); - $this->assertDef('-4', false); - $this->assertDef('asdf', false); - - } - -} - -?> \ No newline at end of file diff --git a/tests/index.php b/tests/index.php index b09713b8..2c605fb8 100644 --- a/tests/index.php +++ b/tests/index.php @@ -61,7 +61,6 @@ $test_files[] = 'AttrDef/TextTest.php'; $test_files[] = 'AttrDef/LangTest.php'; $test_files[] = 'AttrDef/PixelsTest.php'; $test_files[] = 'AttrDef/LengthTest.php'; -$test_files[] = 'AttrDef/NumberSpanTest.php'; $test_files[] = 'AttrDef/URITest.php'; $test_files[] = 'AttrDef/CSSTest.php'; $test_files[] = 'AttrDef/CompositeTest.php';