/** * * 检查object名称格式是否正确,如果非法抛出异常 * * @param $options * @throws OssException */ private function authPrecheckObject($options) { if (isset($options[self::OSS_OBJECT]) && $options[self::OSS_OBJECT] === '/') { return; } if (isset($options[self::OSS_OBJECT]) && !OssUtil::validateObject($options[self::OSS_OBJECT])) { throw new OssException('"' . $options[self::OSS_OBJECT] . '"' . ' object name is invalid'); } }
public function testValidateObject() { $this->assertTrue(OssUtil::validateObject("xxx")); $this->assertTrue(OssUtil::validateObject("xxx23")); $this->assertTrue(OssUtil::validateObject("12321-xxx")); $this->assertTrue(OssUtil::validateObject("x")); $this->assertFalse(OssUtil::validateObject("/aa")); $this->assertFalse(OssUtil::validateObject("\\aa")); $this->assertFalse(OssUtil::validateObject("")); }