. */ class Validation { public static function validate_path($path) { /* Path validation #1 * no '.' or '..' as elements of path, i.e. no '.' nor '..' * at the beginning, at the end, and between slashes. * also this catches doubled slashes */ if(preg_match('#(^|/)(|\.|\.\.)(/|$)#', $path)) return false; /* Path validation #2 * no null characters */ if(preg_match('#\0#', $path)) return false; return true; } public static function validate_hash($hash) { /* Hash validation #1 * regular hashes [a-f0-9] are always ok */ if(preg_match('#^[a-f0-9]{1,40}$#i', $hash)) return true; /* Hash validation #2 * must be a valid path */ if(!self::validate_path($hash)) return false; /* Hash validation #3 * restrictions on ref name according to git-check-ref-format */ if(preg_match('#(\.|\.\.|[\000-\040\177 ~^:?*\[\]]|/$)#', $hash)) return false; return true; } } ?>