Skip to content

Commit

Permalink
Merge pull request #37 from slackhq/fix-null-string-comparison
Browse files Browse the repository at this point in the history
Fix null string comparison
  • Loading branch information
JPolacek authored Dec 6, 2021
2 parents ccea8da + 75c931f commit 756bd40
Show file tree
Hide file tree
Showing 23 changed files with 45 additions and 45 deletions.
2 changes: 1 addition & 1 deletion src/Arborize.hack
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class HTMLPurifier_Arborize {
if ($level > 0) {
$tokens[] = $start;
}
if ($end !== NULL) {
if ($end is nonnull) {
if (C\contains_key($closingTokens, $level)) {
$closingTokens[$level]->push($end);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/AttrDef/CSS/FontFamily.hack
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class HTMLPurifier_AttrDef_CSS_FontFamily extends HTMLPurifier\HTMLPurifier_Attr

// $font is a pure representation of the font name

if ($allowed_fonts !== null && !C\contains_key($allowed_fonts, $font)) {
if ($allowed_fonts is nonnull && !C\contains_key($allowed_fonts, $font)) {
continue;
}

Expand Down
4 changes: 2 additions & 2 deletions src/AttrDef/CSS/Length.hack
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class HTMLPurifier_AttrDef_CSS_Length extends HTMLPurifier\HTMLPurifier_AttrDef
* @param HTMLPurifier_Length|string $max Maximum length, or null for no bound. String is also acceptable.
*/
public function __construct(?string $min = null, ?string $max = null): void {
$this->min = $min !== null ? HTMLPurifier\HTMLPurifier_Length::make($min) : null;
$this->max = $max !== null ? HTMLPurifier\HTMLPurifier_Length::make($max) : null;
$this->min = $min is nonnull ? HTMLPurifier\HTMLPurifier_Length::make($min) : null;
$this->max = $max is nonnull ? HTMLPurifier\HTMLPurifier_Length::make($max) : null;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/AttrDef/HTML/Pixels.hack
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class HTMLPurifier_AttrDef_HTML_Pixels extends HTMLPurifier\HTMLPurifier_AttrDef
// crash operating systems, see <http://ha.ckers.org/imagecrash.html>
// WARNING, above link WILL crash you if you're using Windows

if ($this->max !== null && $int > $this->max) {
if ($this->max is nonnull && $int > $this->max) {
return (string)$this->max;
}
return (string)$int;
Expand Down
2 changes: 1 addition & 1 deletion src/AttrValidator.hack
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class HTMLPurifier_AttrValidator {
}

// put the results into effect
if (($result === '' && $value !== '') || $result === null) {
if (($result === '' && $value !== '') || $result is null) {
// this is a generic error message that should replaced
// with more specific ones when possible
// if ($e) {
Expand Down
2 changes: 1 addition & 1 deletion src/ChildDef/List.hack
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class HTMLPurifier_ChildDef_List extends HTMLPurifier\HTMLPurifier_ChildDef {
// to handle non-list elements; non-list elements should
// not be appended to an existing li; only li created
// for non-list. This distinction is not currently made.
if ($current_li === null) {
if ($current_li is null) {
$current_li = new Node\HTMLPurifier_Node_Element('li');
$result[] = $current_li;
$current_li->children[] = $node;
Expand Down
2 changes: 1 addition & 1 deletion src/Config.hack
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ class HTMLPurifier_Config {
if ($def->setup && !$optimized) {
throw new \Exception("Cannot retrieve raw definition after it has already been setup");
}
if ($def->optimized === null) {
if ($def->optimized is null) {
throw new \Exception("Optimization status of definition is unknown");

}
Expand Down
2 changes: 1 addition & 1 deletion src/ConfigSchema.hack
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ class HTMLPurifier_ConfigSchema {
public function instance(?HTMLPurifier_ConfigSchema $prototype = null): HTMLPurifier_ConfigSchema {
if ($prototype) {
$this->singleton = $prototype;
} else if ($this->singleton === null) {
} else if ($this->singleton is null) {
$this->singleton = HTMLPurifier_ConfigSchema::makeFromSerial();
}
return $this->singleton;
Expand Down
4 changes: 2 additions & 2 deletions src/Definition/CSSDefinition.hack
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ class HTMLPurifier_CSSDefinition extends HTMLPurifier\HTMLPurifier_Definition {
// setup allowed elements
$support = "(for information on implementing this, see the "."support forums) ";
$allowed_properties = $config->def->defaults['CSS.AllowedProperties'];
if ($allowed_properties !== null) {
if ($allowed_properties is nonnull) {
foreach ($this->info as $name => $d) {
if (C\contains_key($allowed_properties, $name) && !$allowed_properties[$name]) {
unset($this->info[$name]);
Expand All @@ -504,7 +504,7 @@ class HTMLPurifier_CSSDefinition extends HTMLPurifier\HTMLPurifier_Definition {
}

$forbidden_properties = $config->def->defaults['CSS.ForbiddenProperties'];
if ($forbidden_properties !== null) {
if ($forbidden_properties is nonnull) {
foreach ($this->info as $name => $d) {
if (C\contains_key($forbidden_properties, $name)) {
unset($this->info[$name]);
Expand Down
6 changes: 3 additions & 3 deletions src/DefinitionCache/Serializer.hack
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ class HTMLPurifier_DefinitionCache_Serializer {
if ($result !== false) {
// set permissions of the new file (no execute)
$chmod = $config->def->defaults['Cache.SerializerPermissions'];
if ($chmod !== null) {
if ($chmod is nonnull) {
// \chmod($file, $chmod & 0666);
}
}
Expand All @@ -287,7 +287,7 @@ class HTMLPurifier_DefinitionCache_Serializer {
private function _prepareDir(HTMLPurifier\HTMLPurifier_Config $config): bool {
$directory = $this->generateDirectoryPath($config);
$chmod = $config->def->defaults['Cache.SerializerPermissions'];
if ($chmod === null) {
if ($chmod is null) {
if (!\mkdir($directory) && !\is_dir($directory)) {
// trigger_error(
// 'Could not create directory ' . $directory . '',
Expand Down Expand Up @@ -343,7 +343,7 @@ class HTMLPurifier_DefinitionCache_Serializer {
// );
return false;
}
if (\function_exists('posix_getuid') && $chmod !== null) {
if (\function_exists('posix_getuid') && $chmod is nonnull) {
// POSIX system, we can give more specific advice
if (\fileowner($dir) === \posix_getuid()) {
// we can chmod it ourselves
Expand Down
8 changes: 4 additions & 4 deletions src/Encoder.hack
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ class HTMLPurifier_Encoder {
public static function iconvAvailable(): bool {
// statics are not permitted in Hack. Making a class with a single static is the work around
// I beleive this to be what Scott was referring to in #help-hacklang
if (StaticIconv::$iconv_bool === null) {
if (StaticIconv::$iconv_bool is null) {
StaticIconv::$iconv_bool = \function_exists('iconv') &&
self::testIconvTruncateBug() != self::ICONV_UNUSABLE;
}
Expand All @@ -360,7 +360,7 @@ class HTMLPurifier_Encoder {
if ($encoding === 'utf-8') {
return $str;
}
if (StaticIconv::$iconv_bool === null) {
if (StaticIconv::$iconv_bool is null) {
StaticIconv::$iconv_bool = self::iconvAvailable();
}
if (StaticIconv::$iconv_bool && !$config->def->defaults['Test.ForceNoIconv']) {
Expand Down Expand Up @@ -408,7 +408,7 @@ class HTMLPurifier_Encoder {
if ($encoding === 'utf-8') {
return $str;
}
if (StaticIconv::$iconv_bool === null) {
if (StaticIconv::$iconv_bool is null) {
StaticIconv::$iconv_bool = self::iconvAvailable();
}
if (StaticIconv::$iconv_bool && !$config->def->defaults['Test.ForceNoIconv']) {
Expand Down Expand Up @@ -496,7 +496,7 @@ class HTMLPurifier_Encoder {
* paying attention to the error code, iconv becomes unusable.
*/
public static function testIconvTruncateBug(): int {
if (StaticCode::$code === null) {
if (StaticCode::$code is null) {
// better not use iconv, otherwise infinite loop!
$unsafe_iconv = self::unsafeIconv('utf-8', 'ascii//IGNORE', "\xCE\xB1".Str\repeat('a', 9000));
$count = Str\length($unsafe_iconv);
Expand Down
2 changes: 1 addition & 1 deletion src/HTMLModuleManager.hack
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ class HTMLPurifier_HTMLModuleManager {

// setup global state variables
$def = null;
if ($trusted === null) {
if ($trusted is null) {
$trusted = $this->trusted;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Injector/AutoParagraph.hack
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ class HTMLPurifier_Injector_AutoParagraph extends HTMLPurifier\HTMLPurifier_Inje
$current = TypeAssert\matches<HTMLPurifier\HTMLPurifier_Token>($this->currentToken);
while ($this->forwardUntilEndToken(inout $i, inout $current, inout $nesting)) {
$result = $this->_checkNeedsP($current);
if ($result !== null) {
if ($result is nonnull) {
$ok = $result;
break;
}
Expand Down
4 changes: 2 additions & 2 deletions src/LanguageFactory.hack
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ class HTMLPurifier_LanguageFactory {
*/
public static function instance(?HTMLPurifier_LanguageFactory $prototype = null): HTMLPurifier_LanguageFactory {
$instance = null;
if ($prototype !== null) {
if ($prototype is nonnull) {
$instance = $prototype;
} else if ($instance === null || $prototype == true) {
} else if ($instance is null || $prototype == true) {
$instance = new HTMLPurifier_LanguageFactory();
}
return $instance;
Expand Down
2 changes: 1 addition & 1 deletion src/Length.hack
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class HTMLPurifier_Length {
* Returns true if this length unit is valid.
*/
public function isValid(HTMLPurifier_Config $config, HTMLPurifier_Context $context): bool {
if ($this->isValid === null) {
if ($this->isValid is null) {
$this->isValid = $this->validate($config, $context);
}
return $this->isValid;
Expand Down
8 changes: 4 additions & 4 deletions src/Strategy/MakeWellFormed.hack
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class HTMLPurifier_Strategy_MakeWellFormed extends HTMLPurifier\HTMLPurifier_Str
unset($injectors['Custom']); // special case
foreach ($injectors as $injector => $b) {
// XXX: Fix with a legitimate lookup table of enabled filters
if (Str\search($injector, '.') !== null) {
if (Str\search($injector, '.') is nonnull) {
continue;
}
if (!$b) {
Expand Down Expand Up @@ -235,7 +235,7 @@ class HTMLPurifier_Strategy_MakeWellFormed extends HTMLPurifier\HTMLPurifier_Str
// See Note [Injector skips]
continue;
}
if ($token->rewind !== null && $token->rewind !== $i) {
if ($token->rewind is nonnull && $token->rewind !== $i) {
continue;
}
$r = $token;
Expand Down Expand Up @@ -317,7 +317,7 @@ class HTMLPurifier_Strategy_MakeWellFormed extends HTMLPurifier\HTMLPurifier_Str
// See Note [Injector skips]
continue;
}
if ($token->rewind !== null && $token->rewind !== $i) {
if ($token->rewind is nonnull && $token->rewind !== $i) {
continue;
}
$r = $token;
Expand Down Expand Up @@ -392,7 +392,7 @@ class HTMLPurifier_Strategy_MakeWellFormed extends HTMLPurifier\HTMLPurifier_Str
// See Note [Injector skips]
continue;
}
if ($token->rewind !== null && $token->rewind !== $i) {
if ($token->rewind is nonnull && $token->rewind !== $i) {
continue;
}
$r = $token;
Expand Down
4 changes: 2 additions & 2 deletions src/Strategy/RemoveForeignElements.hack
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class HTMLPurifier_Strategy_RemoveForeignElements extends HTMLPurifier\HTMLPurif
$trusted = $config->def->defaults['HTML.Trusted'];
$comment_lookup = $config->def->defaults['HTML.AllowedComments'];
$comment_regexp = $config->def->defaults['HTML.AllowedCommentsRegexp'];
$check_comments = $comment_lookup !== vec<string>[] || $comment_regexp != null;
$check_comments = $comment_lookup !== vec<string>[] || $comment_regexp is nonnull;

$remove_script_contents = $config->def->defaults['Core.RemoveScriptContents'];
$hidden_elements = $config->def->defaults['Core.HiddenElements'];
Expand Down Expand Up @@ -180,7 +180,7 @@ class HTMLPurifier_Strategy_RemoveForeignElements extends HTMLPurifier\HTMLPurif
if (
$trusted ||
C\contains($comment_lookup, Str\trim($token->data)) ||
($comment_regexp !== null && \preg_match($comment_regexp, Str\trim($token->data)))
($comment_regexp is nonnull && \preg_match($comment_regexp, Str\trim($token->data)))
) {
// OK good
if ($e) {
Expand Down
2 changes: 1 addition & 1 deletion src/URI.hack
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ class HTMLPurifier_URI {
* @return bool
*/
public function isLocal(HTMLPurifier_Config $config, HTMLPurifier_Context $_context): bool {
if ($this->host === null) {
if ($this->host is null) {
return true;
}
$uri_def = TypeAssert\instance_of(Definition\HTMLPurifier_URIDefinition::class, $config->getURIDefinition());
Expand Down
2 changes: 1 addition & 1 deletion src/URIFilter/SafeIframe.hack
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class HTMLPurifier_URIFilter_SafeIframe extends HTMLPurifier\HTMLPurifier_URIFil
return true;
}
// check if we actually have some allowlists enabled
if ($this->regexp === null) {
if ($this->regexp is null) {
return false;
}
// actually check the allowlists
Expand Down
2 changes: 1 addition & 1 deletion src/URIParser.hack
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class HTMLPurifier_URIParser {
$fragment = (8 < C\count($matches)) ? $matches[9] : '';

// further parse authority
if ($authority !== null) {
if ($authority is nonnull) {
$r_authority = "/^((.+?)@)?(\[[^\]]+\]|[^:]*)(:(\d*))?/";
$matches = vec[];
\preg_match_with_matches($r_authority, $authority, inout $matches);
Expand Down
10 changes: 5 additions & 5 deletions src/URIScheme/data.hack
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ class HTMLPurifier_URIScheme_data extends HTMLPurifier\HTMLPurifier_URIScheme {
if (Str\slice($cur, 0, 8) == 'charset=') {
// doesn't match if there are arbitrary spaces, but
// whatever dude
if ($charset !== null) {
if ($charset is nonnull) {
continue;
} // garbage
$charset = Str\slice($cur, 8); // not used
} else {
if ($content_type !== null) {
if ($content_type is nonnull) {
continue;
} // garbage
$content_type = $cur;
Expand All @@ -73,10 +73,10 @@ class HTMLPurifier_URIScheme_data extends HTMLPurifier\HTMLPurifier_URIScheme {
} else {
$data = $result[0];
}
if ($content_type !== null && !C\contains_key($this->allowed_types, $content_type)) {
if ($content_type is nonnull && !C\contains_key($this->allowed_types, $content_type)) {
return false;
}
if ($charset !== null) {
if ($charset is nonnull) {
// error; we don't allow plaintext stuff
$charset = null;
}
Expand Down Expand Up @@ -130,7 +130,7 @@ class HTMLPurifier_URIScheme_data extends HTMLPurifier\HTMLPurifier_URIScheme {
$uri->port = 0;
$uri->fragment = '';
$uri->query = '';
$uri->path = (string)$content_type.";base64," . \base64_encode($raw_data);
$uri->path = (string)$content_type.";base64,".\base64_encode($raw_data);
return true;
}

Expand Down
4 changes: 2 additions & 2 deletions src/URISchemeRegistry.hack
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ class HTMLPurifier_URISchemeRegistry {
*/
public static function instance(?HTMLPurifier_URISchemeRegistry $prototype = null): HTMLPurifier_URISchemeRegistry {
$instance = null;
if ($prototype !== null) {
if ($prototype is nonnull) {
$instance = $prototype;
} elseif ($instance === null || $prototype == true) {
} elseif ($instance is null || $prototype == true) {
$instance = new HTMLPurifier_URISchemeRegistry();
}
return $instance;
Expand Down
12 changes: 6 additions & 6 deletions src/Zipper.hack
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class HTMLPurifier_Zipper<T> {
*/
public function toArray(?T $t = null): vec<T> {
$a = $this->front;
if ($t !== null) $a[] = $t;
if ($t is nonnull) $a[] = $t;
for ($i = C\count($this->back) - 1; $i >= 0; $i--) {
$a[] = $this->back[$i];
}
Expand All @@ -65,7 +65,7 @@ class HTMLPurifier_Zipper<T> {
* exist in Hack
*/
public function next(?T $t): ?T {
if ($t !== null) {
if ($t is nonnull) {
$this->front[] = $t;
}
$ret = C\last($this->back);
Expand All @@ -92,7 +92,7 @@ class HTMLPurifier_Zipper<T> {
* @return Original contents of new hole.
*/
public function prev(?T $t): ?T {
if ($t !== null) {
if ($t is nonnull) {
$this->back[] = $t;
}
$ret = C\last($this->front);
Expand Down Expand Up @@ -127,14 +127,14 @@ class HTMLPurifier_Zipper<T> {
* Insert element before hole.
*/
public function insertBefore(T $t): void {
if ($t !== NULL) $this->front[] = $t;
if ($t is nonnull) $this->front[] = $t;
}

/**
* Insert element after hole.
*/
public function insertAfter(T $t): void {
if ($t !== NULL) $this->back[] = $t;
if ($t is nonnull) $this->back[] = $t;
}

/**
Expand Down Expand Up @@ -167,7 +167,7 @@ class HTMLPurifier_Zipper<T> {
}
// insert
for ($i = C\count($replacement) - 1; $i >= 0; $i--) {
if ($r !== null) $this->insertAfter($r);
if ($r is nonnull) $this->insertAfter($r);
$r = $replacement[$i];
}
return tuple($old, $r);
Expand Down

0 comments on commit 756bd40

Please sign in to comment.