From 4277624a0c4710507f398e5ef9c7e77ccc6392fe Mon Sep 17 00:00:00 2001 From: Darko Hrgovic Date: Wed, 10 Jul 2019 10:53:31 -0700 Subject: [PATCH] Prepended constants with C_ to avoid reserved words as per https://www.php.net/manual/en/reserved.other-reserved-words.php --- library/HTMLPurifier/Printer/ConfigForm.php | 4 ++-- library/HTMLPurifier/VarParser.php | 32 +++++++++++++-------------- library/HTMLPurifier/VarParser/Flexible.php | 10 ++++----- tests/HTMLPurifier/ConfigSchemaTest.php | 8 +++---- tests/HTMLPurifier/VarParser/FlexibleTest.php | 2 +- 5 files changed, 28 insertions(+), 28 deletions(-) diff --git a/library/HTMLPurifier/Printer/ConfigForm.php b/library/HTMLPurifier/Printer/ConfigForm.php index 65a77790..33ae1139 100644 --- a/library/HTMLPurifier/Printer/ConfigForm.php +++ b/library/HTMLPurifier/Printer/ConfigForm.php @@ -48,7 +48,7 @@ class HTMLPurifier_Printer_ConfigForm extends HTMLPurifier_Printer $this->compress = $compress; // initialize sub-printers $this->fields[0] = new HTMLPurifier_Printer_ConfigForm_default(); - $this->fields[HTMLPurifier_VarParser::BOOL] = new HTMLPurifier_Printer_ConfigForm_bool(); + $this->fields[HTMLPurifier_VarParser::C_BOOL] = new HTMLPurifier_Printer_ConfigForm_bool(); } /** @@ -339,7 +339,7 @@ class HTMLPurifier_Printer_ConfigForm_default extends HTMLPurifier_Printer $value = ''; } } - if ($type === HTMLPurifier_VarParser::MIXED) { + if ($type === HTMLPurifier_VarParser::C_MIXED) { return 'Not supported'; $value = serialize($value); } diff --git a/library/HTMLPurifier/VarParser.php b/library/HTMLPurifier/VarParser.php index 50cba691..0c97c828 100644 --- a/library/HTMLPurifier/VarParser.php +++ b/library/HTMLPurifier/VarParser.php @@ -7,34 +7,34 @@ class HTMLPurifier_VarParser { - const STRING = 1; + const C_STRING = 1; const ISTRING = 2; const TEXT = 3; const ITEXT = 4; - const INT = 5; - const FLOAT = 6; - const BOOL = 7; + const C_INT = 5; + const C_FLOAT = 6; + const C_BOOL = 7; const LOOKUP = 8; const ALIST = 9; const HASH = 10; - const MIXED = 11; + const C_MIXED = 11; /** * Lookup table of allowed types. Mainly for backwards compatibility, but * also convenient for transforming string type names to the integer constants. */ public static $types = array( - 'string' => self::STRING, + 'string' => self::C_STRING, 'istring' => self::ISTRING, 'text' => self::TEXT, 'itext' => self::ITEXT, - 'int' => self::INT, - 'float' => self::FLOAT, - 'bool' => self::BOOL, + 'int' => self::C_INT, + 'float' => self::C_FLOAT, + 'bool' => self::C_BOOL, 'lookup' => self::LOOKUP, 'list' => self::ALIST, 'hash' => self::HASH, - 'mixed' => self::MIXED + 'mixed' => self::C_MIXED ); /** @@ -42,7 +42,7 @@ class HTMLPurifier_VarParser * allowed value lists. */ public static $stringTypes = array( - self::STRING => true, + self::C_STRING => true, self::ISTRING => true, self::TEXT => true, self::ITEXT => true, @@ -74,7 +74,7 @@ class HTMLPurifier_VarParser // These are basic checks, to make sure nothing horribly wrong // happened in our implementations. switch ($type) { - case (self::STRING): + case (self::C_STRING): case (self::ISTRING): case (self::TEXT): case (self::ITEXT): @@ -85,17 +85,17 @@ class HTMLPurifier_VarParser $var = strtolower($var); } return $var; - case (self::INT): + case (self::C_INT): if (!is_int($var)) { break; } return $var; - case (self::FLOAT): + case (self::C_FLOAT): if (!is_float($var)) { break; } return $var; - case (self::BOOL): + case (self::C_BOOL): if (!is_bool($var)) { break; } @@ -119,7 +119,7 @@ class HTMLPurifier_VarParser } } return $var; - case (self::MIXED): + case (self::C_MIXED): return $var; default: $this->errorInconsistent(get_class($this), $type); diff --git a/library/HTMLPurifier/VarParser/Flexible.php b/library/HTMLPurifier/VarParser/Flexible.php index b15016c5..3bfbe838 100644 --- a/library/HTMLPurifier/VarParser/Flexible.php +++ b/library/HTMLPurifier/VarParser/Flexible.php @@ -23,23 +23,23 @@ class HTMLPurifier_VarParser_Flexible extends HTMLPurifier_VarParser // Note: if code "breaks" from the switch, it triggers a generic // exception to be thrown. Specific errors can be specifically // done here. - case self::MIXED: + case self::C_MIXED: case self::ISTRING: - case self::STRING: + case self::C_STRING: case self::TEXT: case self::ITEXT: return $var; - case self::INT: + case self::C_INT: if (is_string($var) && ctype_digit($var)) { $var = (int)$var; } return $var; - case self::FLOAT: + case self::C_FLOAT: if ((is_string($var) && is_numeric($var)) || is_int($var)) { $var = (float)$var; } return $var; - case self::BOOL: + case self::C_BOOL: if (is_int($var) && ($var === 0 || $var === 1)) { $var = (bool)$var; } elseif (is_string($var)) { diff --git a/tests/HTMLPurifier/ConfigSchemaTest.php b/tests/HTMLPurifier/ConfigSchemaTest.php index 6b228bab..40b5868e 100644 --- a/tests/HTMLPurifier/ConfigSchemaTest.php +++ b/tests/HTMLPurifier/ConfigSchemaTest.php @@ -15,12 +15,12 @@ class HTMLPurifier_ConfigSchemaTest extends HTMLPurifier_Harness $this->schema->add('Car.Seats', 5, 'int', false); $this->assertIdentical($this->schema->defaults['Car.Seats'], 5); - $this->assertIdentical($this->schema->info['Car.Seats']->type, HTMLPurifier_VarParser::INT); + $this->assertIdentical($this->schema->info['Car.Seats']->type, HTMLPurifier_VarParser::C_INT); $this->schema->add('Car.Age', null, 'int', true); $this->assertIdentical($this->schema->defaults['Car.Age'], null); - $this->assertIdentical($this->schema->info['Car.Age']->type, HTMLPurifier_VarParser::INT); + $this->assertIdentical($this->schema->info['Car.Age']->type, HTMLPurifier_VarParser::C_INT); } @@ -35,7 +35,7 @@ class HTMLPurifier_ConfigSchemaTest extends HTMLPurifier_Harness ); $this->assertIdentical($this->schema->defaults['QuantumNumber.Difficulty'], null); - $this->assertIdentical($this->schema->info['QuantumNumber.Difficulty']->type, HTMLPurifier_VarParser::STRING); + $this->assertIdentical($this->schema->info['QuantumNumber.Difficulty']->type, HTMLPurifier_VarParser::C_STRING); $this->assertIdentical($this->schema->info['QuantumNumber.Difficulty']->allow_null, true); $this->assertIdentical($this->schema->info['QuantumNumber.Difficulty']->allowed, array( @@ -70,7 +70,7 @@ class HTMLPurifier_ConfigSchemaTest extends HTMLPurifier_Harness ); $this->assertIdentical($this->schema->defaults['Abbrev.HTH'], 'Happy to Help'); - $this->assertIdentical($this->schema->info['Abbrev.HTH']->type, HTMLPurifier_VarParser::STRING); + $this->assertIdentical($this->schema->info['Abbrev.HTH']->type, HTMLPurifier_VarParser::C_STRING); $this->assertIdentical($this->schema->info['Abbrev.HTH']->allowed, array( 'Happy to Help' => true, diff --git a/tests/HTMLPurifier/VarParser/FlexibleTest.php b/tests/HTMLPurifier/VarParser/FlexibleTest.php index ea4469c7..a56c75f8 100644 --- a/tests/HTMLPurifier/VarParser/FlexibleTest.php +++ b/tests/HTMLPurifier/VarParser/FlexibleTest.php @@ -53,7 +53,7 @@ class HTMLPurifier_VarParser_FlexibleTest extends HTMLPurifier_VarParserHarness public function testValidate_withMagicNumbers() { - $this->assertValid('foobar', HTMLPurifier_VarParser::STRING); + $this->assertValid('foobar', HTMLPurifier_VarParser::C_STRING); } public function testValidate_null() -- 2.11.4.GIT