Changeset View
Changeset View
Standalone View
Standalone View
src/parser/PhutilURI.php
Show First 20 Lines • Show All 344 Lines • ▼ Show 20 Lines | private function isGitURIPattern($uri) { | ||||
$last = $matches['last']; | $last = $matches['last']; | ||||
// If any part of this has spaces in it, it's not a Git URI. We fail here | // If any part of this has spaces in it, it's not a Git URI. We fail here | ||||
// so we fall back and don't fail more abruptly later. | // so we fall back and don't fail more abruptly later. | ||||
if (preg_match('(\s)', $head.$last)) { | if (preg_match('(\s)', $head.$last)) { | ||||
return false; | return false; | ||||
} | } | ||||
// If the second part only contains digits, assume we're looking at | |||||
// casually specified "domain.com:123" URI, not a Git URI pointed at an | |||||
// entirely numeric relative path. | |||||
if (preg_match('(^\d+\z)', $last)) { | |||||
return false; | |||||
} | |||||
// If the first part has a "." or an "@" in it, interpret it as a domain | // If the first part has a "." or an "@" in it, interpret it as a domain | ||||
// or a "user@host" string. | // or a "user@host" string. | ||||
if (preg_match('([.@])', $head)) { | if (preg_match('([.@])', $head)) { | ||||
return true; | return true; | ||||
} | } | ||||
// 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; | ||||
} | } | ||||
} | } |