Skip to content

Commit

Permalink
index: hard-limit the description field.
Browse files Browse the repository at this point in the history
  • Loading branch information
FacuM committed Mar 17, 2021
1 parent 67158b4 commit d177560
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions includes/constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
'HEIGHT' => 300
]);

define('DESCRIPTION_MAX_LENGTH', 200);

define('HTTP_STATUS', [
'OK' => 200,
'CREATED' => 201,
Expand Down
2 changes: 1 addition & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class="modal fade"
<form>
<div class="form-group">
<label for="serverDescription" class="col-form-label"> Description </label>
<textarea class="form-control" id="serverDescription"></textarea>
<textarea class="form-control" id="serverDescription" maxlength="200"></textarea>
<div class="invalid-feedback">
Please provide a valid description.
</div>
Expand Down
6 changes: 6 additions & 0 deletions services/serverListManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,12 @@
);
}

if (strlen($validData['description']) > DESCRIPTION_MAX_LENGTH) {
$validData['description'] = substr($validData['description'], 0, DESCRIPTION_MAX_LENGTH);

$result['notice'] = 'The description provided was too long, truncated to ' . DESCRIPTION_MAX_LENGTH . ' characters.';
}

$statement->bindValue('description' , $validData['description']);
$statement->bindValue('hostname' , $validData['hostname']);
$statement->bindValue('ip' , $validData['ipAddress']);
Expand Down

0 comments on commit d177560

Please sign in to comment.