From 94c2b5a7132efa27c0e477bc12b9beca54c1695e Mon Sep 17 00:00:00 2001 From: Basile Burg Date: Wed, 27 Mar 2019 17:17:52 +0100 Subject: [PATCH] dastworx, todo list fixes * fix special char literals for pascal strings not verified when the text doesn't contain a single quote. * fix len limit not applied correctly * fix single quote after special char put unconditionally * prevent loading when deserialization fail --- dastworx/src/common.d | 20 ++++++++++++++------ src/u_todolist.pas | 7 ++++++- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/dastworx/src/common.d b/dastworx/src/common.d index acadd38e..11a1366d 100644 --- a/dastworx/src/common.d +++ b/dastworx/src/common.d @@ -197,10 +197,14 @@ string patchPascalString(size_t lenLimit = 0)(string value) { bool needed; foreach(i; 0 .. value.length) - if (value[i] == '\'') + switch (value[i]) { - needed = true; - break; + case '\'' : + case '\r' : + case '\n' : + needed = true; + break; + default: } if (!needed) return value; @@ -212,7 +216,7 @@ string patchPascalString(size_t lenLimit = 0)(string value) const size_t len = value.length; app.reserve(len); bool skip; - L: foreach (immutable i; 0..value.length) + L: foreach (immutable i; 0..len) { const char c = value[i]; switch (c) @@ -228,7 +232,9 @@ string patchPascalString(size_t lenLimit = 0)(string value) if (skip) app ~= value[i]; else - app ~= "'#39'"; + app ~= "'#39"; + if (i != len-1) + app ~= "'"; skip = false; break; } @@ -237,7 +243,9 @@ string patchPascalString(size_t lenLimit = 0)(string value) if (skip) app ~= value[i]; else - app ~= "'#10'"; + app ~= "'#10"; + if (i != len-1) + app ~= "'"; skip = false; break; } diff --git a/src/u_todolist.pas b/src/u_todolist.pas index d09e48c6..035648b1 100644 --- a/src/u_todolist.pas +++ b/src/u_todolist.pas @@ -491,7 +491,12 @@ end; procedure TTodoListWidget.toolTerminated(Sender: TObject); begin fToolProc.StdoutEx.Position := 0; - fTodos.loadFromTxtStream(fToolProc.StdoutEx); + try + fTodos.loadFromTxtStream(fToolProc.StdoutEx); + except + fToolProc.OnTerminate := nil; + exit; + end; fillTodoList; fToolProc.OnTerminate := nil; end;