From 3e83d564424dcd3257a808cae041731e8fdccf08 Mon Sep 17 00:00:00 2001 From: Greg Chapman <75333244+gregchapman-dev@users.noreply.github.com> Date: Tue, 21 Nov 2023 14:07:35 -0800 Subject: [PATCH] Fix stripDateError() crash and never emit empty date@isodate. --- src/iohumdrum.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/iohumdrum.cpp b/src/iohumdrum.cpp index 1023e0b1f36..34b26556e3e 100644 --- a/src/iohumdrum.cpp +++ b/src/iohumdrum.cpp @@ -3064,6 +3064,10 @@ std::map HumdrumInput::isoDateAttributesFromHumdrumDat std::vector isodates; for (auto const &date : dates) { std::string isodate = isoDateFromDateWithErrors(date, edtf); + if (isodate.empty()) { + // date not representable as isodate; bail on all isodates for this piece of metadata + return attribs; + } isodates.push_back(isodate); } @@ -3410,8 +3414,17 @@ std::string HumdrumInput::stripDateError(std::string &value) if (idx == SIZE_MAX) { return ""; } - char errorStr[1]; - errorStr[0] = value[idx]; + std::string errorStr; + if (value[idx] == '?') { + // we have to escape it (twice) to put it in a regex + errorStr = "\\?"; + } + else { + char chars[2]; + chars[0] = value[idx]; + chars[1] = 0; + errorStr = chars; + } hum::HumRegex hre; hre.replaceDestructive(value, "", errorStr);