From 3c089f5d1674f9d5dca62f298e7272fc3dd05bcf Mon Sep 17 00:00:00 2001 From: keplyx Date: Fri, 15 Nov 2019 16:14:00 +0100 Subject: [PATCH] Sanitize fields before saving --- assets/js/stock.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/assets/js/stock.js b/assets/js/stock.js index 337eb23..56321d9 100644 --- a/assets/js/stock.js +++ b/assets/js/stock.js @@ -89,10 +89,10 @@ function getItemOfCode(code) { function addNewItem() { if (isItemInputFilled()) { let item = { - name: $.selector_cache('#nameInput').val(), - description: $.selector_cache('#descriptionInput').val(), - quantity: $.selector_cache('#quantityInput').val(), - price: $.selector_cache('#priceInput').val(), + name: sanitizeString($.selector_cache('#nameInput').val()), + description: sanitizeString($.selector_cache('#descriptionInput').val()), + quantity: sanitizeNumber($.selector_cache('#quantityInput').val()), + price: sanitizeNumber($.selector_cache('#priceInput').val()), code: $.selector_cache('#codeInput').val(), type: getTypesChecked(), image: $.selector_cache('#imageInput').val(), @@ -192,7 +192,13 @@ function saveDataset() { SaveManager.saveData(currentTypes, currentDataset); } +function sanitizeString(str) { + return str.trim(); +} +function sanitizeNumber(nbrStr) { + return nbrStr.replace(/\s/g,''); +} function scanArticle(code) { let data = {