Changeset View
Changeset View
Standalone View
Standalone View
src/parser/PhutilURI.php
Show First 20 Lines • Show All 555 Lines • ▼ Show 20 Lines | private function isGitURIPattern($uri) { | ||||
// Otherwise, interpret the URI conservatively as a "javascript:"-style | // Otherwise, interpret the URI conservatively as a "javascript:"-style | ||||
// URI. This means that "localhost:path" is parsed as a normal URI instead | // URI. This means that "localhost:path" is parsed as a normal URI instead | ||||
// of a Git URI, but we can't tell which the user intends and it's safer | // of a Git URI, but we can't tell which the user intends and it's safer | ||||
// to treat it as a normal URI. | // to treat it as a normal URI. | ||||
return false; | return false; | ||||
} | } | ||||
/** | |||||
* This is just a complicated type-check - we'll eventually replace it with a | |||||
* native type-hint of `PhutilURI | string | null`, when this type-hint is | |||||
* available (php 8.0). | |||||
* | |||||
* Before php 8, and after we suspect there aren't many more cases where this | |||||
* fails, we'll replace the log with an exception. | |||||
*/ | |||||
public static function checkHrefType($value) { | |||||
if ($value === null || is_string($value)) { | |||||
valerio.bozzolan: I like that, premising that we can replace `gettype($value) == 'string'` with `is_string… | |||||
Done Inline ActionsI did a grep, and I can't find any place where we do gettype() == 'string', but we do have a bunch of is_string(), so is_string is probably better. avivey: I did a grep, and I can't find any place where we do `gettype() == 'string'`, but we do have a… | |||||
return; | |||||
} | |||||
if ($value instanceof PhutilURI) { | |||||
return; | |||||
} | |||||
$report_type = is_object($value) ? get_class($value) : gettype($value); | |||||
// We log stuff with a kind stack trace | |||||
phlog( | |||||
pht( | |||||
'Unexpected value type provided for an HREF field - %s. '. | |||||
'Please share this stack trace as comment in Task %s', | |||||
$report_type, | |||||
'https://we.phorge.it/T15316')); | |||||
} | |||||
} | } |
Content licensed under Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) unless otherwise noted; code licensed under Apache 2.0 or other open source licenses. · CC BY-SA 4.0 · Apache 2.0
I like that, premising that we can replace gettype($value) == 'string' with is_string($value)
https://www.php.net/manual/en/function.is-string.php
Also Using is_string() on an object will always return false (even with __toString()).
The last thing is not officially documented thought, so, probably the gettype() check is better