kopia lustrzana https://github.com/nextcloud/social
validate tags (mention and hashtags) on incoming request
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>pull/295/head
rodzic
01ed889984
commit
cb7583c68c
|
@ -59,6 +59,7 @@ class ACore extends Item implements JsonSerializable {
|
||||||
const AS_USERNAME = 5;
|
const AS_USERNAME = 5;
|
||||||
const AS_ACCOUNT = 6;
|
const AS_ACCOUNT = 6;
|
||||||
const AS_STRING = 7;
|
const AS_STRING = 7;
|
||||||
|
const AS_TAGS = 10;
|
||||||
|
|
||||||
|
|
||||||
/** @var null Item */
|
/** @var null Item */
|
||||||
|
@ -449,7 +450,11 @@ class ACore extends Item implements JsonSerializable {
|
||||||
$result = [];
|
$result = [];
|
||||||
foreach ($values as $value) {
|
foreach ($values as $value) {
|
||||||
try {
|
try {
|
||||||
|
if (is_array($value)) {
|
||||||
|
$result[] = $this->validateEntryArray($as, $value);
|
||||||
|
} else {
|
||||||
$result[] = $this->validateEntryString($as, $value);
|
$result[] = $this->validateEntryString($as, $value);
|
||||||
|
}
|
||||||
} catch (InvalidResourceEntryException $e) {
|
} catch (InvalidResourceEntryException $e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -461,13 +466,14 @@ class ACore extends Item implements JsonSerializable {
|
||||||
/**
|
/**
|
||||||
* // TODO - better checks
|
* // TODO - better checks
|
||||||
*
|
*
|
||||||
* @param $as
|
* @param int $as
|
||||||
* @param $value
|
* @param string $value
|
||||||
|
* @param bool $exception
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
* @throws InvalidResourceEntryException
|
* @throws InvalidResourceEntryException
|
||||||
*/
|
*/
|
||||||
public function validateEntryString(int $as, string $value): string {
|
public function validateEntryString(int $as, string $value, bool $exception = true): string {
|
||||||
switch ($as) {
|
switch ($as) {
|
||||||
case self::AS_ID:
|
case self::AS_ID:
|
||||||
if (parse_url($value) !== false) {
|
if (parse_url($value) !== false) {
|
||||||
|
@ -502,12 +508,41 @@ class ACore extends Item implements JsonSerializable {
|
||||||
$value = strip_tags($value);
|
$value = strip_tags($value);
|
||||||
|
|
||||||
return $value;
|
return $value;
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($exception) {
|
||||||
throw new InvalidResourceEntryException($as . ' ' . $value);
|
throw new InvalidResourceEntryException($as . ' ' . $value);
|
||||||
|
} else {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $as
|
||||||
|
* @param array $values
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
* @throws InvalidResourceEntryException
|
||||||
|
*/
|
||||||
|
public function validateEntryArray(int $as, array $values): array {
|
||||||
|
switch ($as) {
|
||||||
|
case self::AS_TAGS:
|
||||||
|
|
||||||
|
return [
|
||||||
|
'type' => $this->validateEntryString(
|
||||||
|
self::AS_TYPE, $this->get('type', $values, ''), false
|
||||||
|
),
|
||||||
|
'href' => $this->validateEntryString(
|
||||||
|
self::AS_URL, $this->get('href', $values, ''), false
|
||||||
|
),
|
||||||
|
'name' => $this->validateEntryString(
|
||||||
|
self::AS_STRING, $this->get('name', $values, ''), false
|
||||||
|
)
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new InvalidResourceEntryException($as . ' ' . json_encode($values));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -524,6 +559,7 @@ class ACore extends Item implements JsonSerializable {
|
||||||
$this->setPublished($this->validate(self::AS_DATE, 'published', $data, ''));
|
$this->setPublished($this->validate(self::AS_DATE, 'published', $data, ''));
|
||||||
$this->setActorId($this->validate(self::AS_ID, 'actor', $data, ''));
|
$this->setActorId($this->validate(self::AS_ID, 'actor', $data, ''));
|
||||||
$this->setObjectId($this->validate(self::AS_ID, 'object', $data, ''));
|
$this->setObjectId($this->validate(self::AS_ID, 'object', $data, ''));
|
||||||
|
$this->setTags($this->validateArray(self::AS_TAGS, 'tags', $data, []));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue