Skip to content
This repository was archived by the owner on Mar 30, 2024. It is now read-only.

Commit b1fb034

Browse files
committed
Add settings edit && snyc input validation
1 parent 320e88d commit b1fb034

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

core/Settings.php

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ private function categories(array $commands) : void {
4848
if( $color == CLIOutput::RED){
4949
$this->output->print(array("Please check input, can't create categories twice, check allowed chars!"), $color ,1);
5050
}
51-
$newcat = $this->output->readline("Name of category to add [Only A-Z, a-z and -]:", $color, 1);
51+
$newcat = $this->output->readline("Name of category to add [Only A-Z, a-z, 0-9 and -]:", $color, 1);
5252
$color = CLIOutput::RED;
5353
} while (!InputParser::checkCategoryInput($newcat) || in_array($newcat, $cats));
5454
$cats[] = $newcat;
@@ -202,13 +202,13 @@ private function editSingle(int $id, JSONReader $s) : void {
202202
else{
203203
$this->output->print(array("For all upcoming, leave empty to remain unchanged."), CLIOutput::BLUE, 1);
204204

205-
$name = trim($this->output->readline("Give a new name:", null, 1));
206-
if( !empty( $name ) ){
205+
$name = trim($this->output->readline("Give a new name [Only A-Z, a-z, 0-9, _ and -]:", null, 1));
206+
if( InputParser::checkNameInput($name) ){
207207
$s->setValue([$id, 'name'], $name);
208208
}
209209

210-
$category = trim($this->output->readline("Give a new category (type a name, not an ID):", null, 1));
211-
if( !empty( $category ) ){
210+
$category = trim($this->output->readline("Give a new category [Use a name containing A-Z, a-z, 0-9 and -, no ID]:", null, 1));
211+
if( InputParser::checkCategoryInput($category) ){
212212
$s->setValue([$id, 'category'], $category);
213213
}
214214

@@ -307,6 +307,13 @@ private function editSync(string $type, JSONReader $c) : void {
307307
'group' => "Sync group",
308308
'token' => "Client token",
309309
);
310+
$check = array(
311+
'path' => fn(string $p) => is_dir($p) && is_writable($p),
312+
'thisname' => fn(string $n) => InputParser::checkDeviceName($n),
313+
'uri' => fn(string $u) => @filter_var($u, FILTER_VALIDATE_URL, FILTER_FLAG_HOST_REQUIRED | FILTER_FLAG_SCHEME_REQUIRED),
314+
'group' => fn(string $g) => preg_match('/^[A-Za-z0-9]+$/', $g) === 1,
315+
'token' => fn(string $t) => preg_match('/^[A-Za-z0-9]+$/', $t) === 1,
316+
);
310317

311318
// setup array or remove sync
312319
if( !$c->isValue(['sync']) ){
@@ -335,9 +342,15 @@ private function editSync(string $type, JSONReader $c) : void {
335342
$input = trim($this->output->readline(
336343
$names[$key] . ':' . ($key != 'thisname' ? "\t\t" : "\t"
337344
), null, 1));
338-
if( !empty($input)){
339-
$unchanged = false;
340-
$c->setValue(['sync', $type, $key], $input);
345+
if( !empty($input) ){
346+
if( isset( $check[$key] ) && !$check[$key]($input) ){
347+
$this->output->print(array("Invalid format! Stays unchanged!"), CLIOutput::RED, 2);
348+
349+
}
350+
else{
351+
$unchanged = false;
352+
$c->setValue(['sync', $type, $key], $input);
353+
}
341354
}
342355
} while( empty( $c->getValue(['sync', $type, $key]) ) );
343356
}

core/Utilities.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55
class Utilities {
66

7-
const VERSION = 'v0.9.4 beta';
7+
const VERSION = 'v0.9.5 beta';
88

99
/**
1010
* OS Consts

0 commit comments

Comments
 (0)