From 4529bcf24a43c6f58ef4d432e745c8348bcc827c Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 9 Aug 2015 10:20:25 -0400 Subject: [PATCH] Import: UUID attribute is now validated --- src/Task.cpp | 14 ++++++++++++-- src/commands/CmdImport.cpp | 3 ++- src/l10n/deu-DEU.h | 1 + src/l10n/eng-USA.h | 1 + src/l10n/epo-RUS.h | 1 + src/l10n/esp-ESP.h | 1 + src/l10n/fra-FRA.h | 1 + src/l10n/ita-ITA.h | 1 + src/l10n/jpn-JPN.h | 1 + src/l10n/pol-POL.h | 1 + src/l10n/por-PRT.h | 1 + 11 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/Task.cpp b/src/Task.cpp index d0c4811ac..647cf5820 100644 --- a/src/Task.cpp +++ b/src/Task.cpp @@ -1404,8 +1404,18 @@ void Task::validate (bool applyDefault /* = true */) Task::status status = getStatus (); // 1) Provide missing attributes where possible - // Provide a UUID if necessary. - if (! has ("uuid") || get ("uuid") == "") + // Provide a UUID if necessary. Validate if present. + std::string uid = get ("uuid"); + if (has ("uuid") && uid != "") + { + Lexer lex (uid); + Lexer::Type type; + if (! lex.token (uid, type) || + uid.length () != 36 || + type != Lexer::Type::uuid) + throw format (STRING_CMD_IMPORT_UUID_BAD, uid); + } + else set ("uuid", uuid ()); // Recurring tasks get a special status. diff --git a/src/commands/CmdImport.cpp b/src/commands/CmdImport.cpp index a7c0a7f4f..669815db5 100644 --- a/src/commands/CmdImport.cpp +++ b/src/commands/CmdImport.cpp @@ -174,8 +174,9 @@ int CmdImport::import (const std::string& input) //////////////////////////////////////////////////////////////////////////////// void CmdImport::importSingleTask (json::object* obj) { - // Parse the whole thing. + // Parse the whole thing, validate the data. Task task (obj); + task.validate (); // Check whether the imported task is new or a modified existing task. Task before; diff --git a/src/l10n/deu-DEU.h b/src/l10n/deu-DEU.h index 70395ad79..b4932ecbf 100644 --- a/src/l10n/deu-DEU.h +++ b/src/l10n/deu-DEU.h @@ -457,6 +457,7 @@ #define STRING_CMD_IMPORT_SUMMARY "{1} Aufgabe importiert." #define STRING_CMD_IMPORT_FILE "Importiere '{1}'" #define STRING_CMD_IMPORT_MISSING "Datei '{1}' nicht gefunden." +#define STRING_CMD_IMPORT_UUID_BAD "Not a valid UUID '{1}'." #define STRING_TASK_NO_DESC "Kommentar fehlt Beschreibung: {1}" #define STRING_TASK_NO_ENTRY "Kommentar fehlt Erfassungsdatum: {1}" #define STRING_CMD_SYNC_USAGE "Gleicht Daten mit dem Task-Server ab" diff --git a/src/l10n/eng-USA.h b/src/l10n/eng-USA.h index ec4b7e4e6..c2824d841 100644 --- a/src/l10n/eng-USA.h +++ b/src/l10n/eng-USA.h @@ -454,6 +454,7 @@ #define STRING_CMD_IMPORT_SUMMARY "Imported {1} tasks." #define STRING_CMD_IMPORT_FILE "Importing '{1}'" #define STRING_CMD_IMPORT_MISSING "File '{1}' not found." +#define STRING_CMD_IMPORT_UUID_BAD "Not a valid UUID '{1}'." #define STRING_TASK_NO_DESC "Annotation is missing a description: {1}" #define STRING_TASK_NO_ENTRY "Annotation is missing an entry date: {1}" #define STRING_CMD_SYNC_USAGE "Synchronizes data with the Taskserver" diff --git a/src/l10n/epo-RUS.h b/src/l10n/epo-RUS.h index e6adcf5c7..1caecc0b0 100644 --- a/src/l10n/epo-RUS.h +++ b/src/l10n/epo-RUS.h @@ -457,6 +457,7 @@ #define STRING_CMD_IMPORT_SUMMARY "Importis {1} taskojn." #define STRING_CMD_IMPORT_FILE "Importanta '{1}'" #define STRING_CMD_IMPORT_MISSING "File '{1}' not found." +#define STRING_CMD_IMPORT_UUID_BAD "Not a valid UUID '{1}'." #define STRING_TASK_NO_DESC "Komento havas mankon de priskribo: {1}" #define STRING_TASK_NO_ENTRY "Komento havas mankon de enskrib-dato: {1}" #define STRING_CMD_SYNC_USAGE "Sinkronigas datumojn kun la Taskserver" diff --git a/src/l10n/esp-ESP.h b/src/l10n/esp-ESP.h index 8d75497c7..05e9c3400 100644 --- a/src/l10n/esp-ESP.h +++ b/src/l10n/esp-ESP.h @@ -465,6 +465,7 @@ #define STRING_CMD_IMPORT_SUMMARY "Importadas {1} tareas." #define STRING_CMD_IMPORT_FILE "Importando '{1}'" #define STRING_CMD_IMPORT_MISSING "Archivo '{1}' no encontrado." +#define STRING_CMD_IMPORT_UUID_BAD "Not a valid UUID '{1}'." #define STRING_TASK_NO_DESC "La anotación carece de descripción: {1}" #define STRING_TASK_NO_ENTRY "La anotación carece de fecha de entrada: {1}" diff --git a/src/l10n/fra-FRA.h b/src/l10n/fra-FRA.h index e4432b3b0..3b79db0e1 100644 --- a/src/l10n/fra-FRA.h +++ b/src/l10n/fra-FRA.h @@ -457,6 +457,7 @@ #define STRING_CMD_IMPORT_SUMMARY "Imported {1} tasks." #define STRING_CMD_IMPORT_FILE "Importing '{1}'" #define STRING_CMD_IMPORT_MISSING "File '{1}' not found." +#define STRING_CMD_IMPORT_UUID_BAD "Not a valid UUID '{1}'." #define STRING_TASK_NO_DESC "Annotation is missing a description: {1}" #define STRING_TASK_NO_ENTRY "Annotation is missing an entry date: {1}" #define STRING_CMD_SYNC_USAGE "Synchronizes data with the Taskserver" diff --git a/src/l10n/ita-ITA.h b/src/l10n/ita-ITA.h index 59dc21cec..ddda8974a 100644 --- a/src/l10n/ita-ITA.h +++ b/src/l10n/ita-ITA.h @@ -456,6 +456,7 @@ #define STRING_CMD_IMPORT_SUMMARY "Importati {1} task." #define STRING_CMD_IMPORT_FILE "Importazione di '{1}'" #define STRING_CMD_IMPORT_MISSING "File '{1}' not found." +#define STRING_CMD_IMPORT_UUID_BAD "Not a valid UUID '{1}'." #define STRING_TASK_NO_DESC "Annotazione senza descrizione: {1}" #define STRING_TASK_NO_ENTRY "Annotazione senza data di immissione: {1}" #define STRING_CMD_SYNC_USAGE "Sincronizza i dati con il Taskserver" diff --git a/src/l10n/jpn-JPN.h b/src/l10n/jpn-JPN.h index f2feafa89..90abee88d 100644 --- a/src/l10n/jpn-JPN.h +++ b/src/l10n/jpn-JPN.h @@ -457,6 +457,7 @@ #define STRING_CMD_IMPORT_SUMMARY "{1} task をインポートしました。" #define STRING_CMD_IMPORT_FILE "'{1}' をインポート中" #define STRING_CMD_IMPORT_MISSING "ファイル '{1}' が見つかりません。" +#define STRING_CMD_IMPORT_UUID_BAD "Not a valid UUID '{1}'." #define STRING_TASK_NO_DESC "Annotation is missing a description: {1}" #define STRING_TASK_NO_ENTRY "Annotation is missing an entry date: {1}" #define STRING_CMD_SYNC_USAGE "Taskserver とデータを同期" diff --git a/src/l10n/pol-POL.h b/src/l10n/pol-POL.h index 997a5c70c..f7a705979 100644 --- a/src/l10n/pol-POL.h +++ b/src/l10n/pol-POL.h @@ -457,6 +457,7 @@ #define STRING_CMD_IMPORT_SUMMARY "Zaimportowano {1} zadań." #define STRING_CMD_IMPORT_FILE "Importowanie '{1}'" #define STRING_CMD_IMPORT_MISSING "File '{1}' not found." +#define STRING_CMD_IMPORT_UUID_BAD "Not a valid UUID '{1}'." #define STRING_TASK_NO_DESC "Komentarz nie posiada treści: {1}" #define STRING_TASK_NO_ENTRY "Komentarz nie posiada daty utworzenia: {1}" #define STRING_CMD_SYNC_USAGE "Synchronizuje dane z serwerem zadań" diff --git a/src/l10n/por-PRT.h b/src/l10n/por-PRT.h index e0f39005d..a1c500103 100644 --- a/src/l10n/por-PRT.h +++ b/src/l10n/por-PRT.h @@ -457,6 +457,7 @@ #define STRING_CMD_IMPORT_SUMMARY "Importadas {1} tarefas." #define STRING_CMD_IMPORT_FILE "A importar '{1}'" #define STRING_CMD_IMPORT_MISSING "File '{1}' not found." +#define STRING_CMD_IMPORT_UUID_BAD "Not a valid UUID '{1}'." #define STRING_TASK_NO_DESC "Descrição da anotação em falta: {1}" #define STRING_TASK_NO_ENTRY "Data de entrada da anotação em falta: {1}" #define STRING_CMD_SYNC_USAGE "Sincroniza dados com o Taskserver"