Browse Source

BUGFIX: Fixed text length not being verified on todo update

master
parent
commit
5c7f0fbf18
  1. 10
      pages/category.html
  2. 20
      src/server/endpoints.go
  3. 4
      src/server/validation.go

10
pages/category.html

@ -57,7 +57,6 @@
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<p id="modalToDoErrorMessage"></p>
<div>
<strong>{{index .Translation "category modal todo text"}}</strong>
<span id="modalTodoTextDisplay"></span>
@ -86,6 +85,7 @@
{{ index .Translation "category file download button"}}
</button>
</div>
<p id="modalToDoErrorMessage" class="text-danger fw-bold"></p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal" onclick="toggleEditMode(false);">{{index .Translation "category modal close button"}}</button>
@ -126,7 +126,6 @@
<div class="row g-3 align-items-center">
<div class="col-md">
<label for="newTodoText" class="form-label">{{index .Translation "category todo text"}}</label>
<!-- <input type="text" class="form-control" id="newTodoText" placeholder='{{index .Translation "category enter todo text"}}' required> -->
<textarea class="form-control" id="newTodoText" placeholder='{{index .Translation "category enter todo text"}}' required></textarea>
</div>
<div class="col-md">
@ -362,7 +361,6 @@ async function saveEditedTodo() {
document.getElementById('modalTodoDueDisplay').innerText = updatedDue;
const updatedDueUnix = Date.parse(updatedDue) / 1000;
let response = await updateTodo(viewedTodoID, {"text":updatedText, "dueUnix":updatedDueUnix, "isDone":false});
if (!response.ok) {
document.getElementById("modalToDoErrorMessage").innerText = await response.text();
@ -371,7 +369,6 @@ async function saveEditedTodo() {
let result = await uploadAttachedFile(viewedTodoID);
if (!result) {
alert("Failed to upload attachment file");
return;
}
@ -410,10 +407,11 @@ async function downloadAttachedFile() {
async function uploadAttachedFile(todoID) {
let todoFileInput = document.getElementById("modalFileInput");
if (todoFileInput.files.length === 0 ) {
return false;
return true;
}
if (todoFileInput.files.item(0).size > 3145728) {
todoFileInput.setCustomValidity("File size exceeded 3MB");
// todoFileInput.setCustomValidity("File size exceeded 3MB");
document.getElementById("modalToDoErrorMessage").innerText = "File size exceeded 3MB";
return false;
}

20
src/server/endpoints.go

@ -561,6 +561,18 @@ func (s *Server) EndpointTodoUpdate(w http.ResponseWriter, req *http.Request) {
return
}
// Validate
if uint(len([]rune(updatedTodo.Text))) > MaxTodoTextLength {
http.Error(
w,
fmt.Sprintf("Text is too big! Text must be less than %d characters long!", MaxTodoTextLength),
http.StatusBadRequest,
)
return
}
updatedTodo.File = nil
updatedTodo.ID = todoID
// Update
err = s.db.UpdateTodoSoft(todoID, updatedTodo)
if err != nil {
@ -694,8 +706,12 @@ func (s *Server) EndpointTodoCreate(w http.ResponseWriter, req *http.Request) {
}
// Check if text is too long or not
if uint(len(newTodo.Text)) > MaxTodoTextLength {
http.Error(w, "Text is too big!", http.StatusBadRequest)
if uint(len([]rune(newTodo.Text))) > MaxTodoTextLength {
http.Error(
w,
fmt.Sprintf("Text is too big! Text must be less than %d characters long!", MaxTodoTextLength),
http.StatusBadRequest,
)
return
}

4
src/server/validation.go

@ -31,8 +31,8 @@ import (
const (
MinimalEmailLength uint = 3
MinimalPasswordLength uint = 5
MaxEmailLength uint = 60
MaxPasswordLength uint = 250
MaxEmailLength uint = 50
MaxPasswordLength uint = 50
MaxTodoTextLength uint = 250
MaxTodoFileSizeBytes uint = 3145728 // 3MB
)

Loading…
Cancel
Save