diff --git a/api/tests/integration/ref/formats/idt_to_ket.py.out b/api/tests/integration/ref/formats/idt_to_ket.py.out index 2e41b85d21..91da009843 100644 --- a/api/tests/integration/ref/formats/idt_to_ket.py.out +++ b/api/tests/integration/ref/formats/idt_to_ket.py.out @@ -31,6 +31,7 @@ idt_unresolved_many.ket:SUCCEED idt_unsplit.ket:SUCCEED Test '!+A-$#12w12r23e32e33': got expected error 'Invalid symbols in the sequence: !,-,$,#,1,2,w,1,2,2,3,e,3,2,e,3,3' Test '(Y:)': got expected error 'Invalid IDT ambiguous monomer (Y:)' +Test '(Y:000010af)': got expected error 'Invalid number 'af'' Test '(YY:00330067)': got expected error 'Invalid mixed base - only numerical index allowed.' Test '+/5Phos/A': got expected error 'Sugar prefix could not be used with modified monomer.' Test '/': got expected error 'Unexpected end of data' diff --git a/api/tests/integration/tests/formats/idt_to_ket.py b/api/tests/integration/tests/formats/idt_to_ket.py index 3b4e85798d..1fa58525f3 100644 --- a/api/tests/integration/tests/formats/idt_to_ket.py +++ b/api/tests/integration/tests/formats/idt_to_ket.py @@ -103,6 +103,7 @@ def find_diff(a, b): "r(B1:50003000)(B1)": "Unknown mixed base 'B1'", "(YY:00330067)": "Invalid mixed base - only numerical index allowed.", "(Y:)": "Invalid IDT ambiguous monomer (Y:)", + "(Y:000010af)": "Invalid number 'af'", } for idt_seq in sorted(idt_errors.keys()): error = idt_errors[idt_seq] diff --git a/core/indigo-core/molecule/src/sequence_loader.cpp b/core/indigo-core/molecule/src/sequence_loader.cpp index a4577433eb..c37279a4a2 100644 --- a/core/indigo-core/molecule/src/sequence_loader.cpp +++ b/core/indigo-core/molecule/src/sequence_loader.cpp @@ -1096,8 +1096,18 @@ void SequenceLoader::loadIdt(KetDocument& document) check_mixed_base(mixed_base); if (ratios_str.size() != 8) throw Exception("Invalid IDT ambiguous monomer %s", idt_alias.c_str()); - ratios.emplace(std::array{std::stof(ratios_str.substr(0, 2)), std::stof(ratios_str.substr(2, 2)), - std::stof(ratios_str.substr(4, 2)), std::stof(ratios_str.substr(6, 2))}); + auto stof = [](const std::string& arg) -> float { + try + { + return std::stof(arg); + } + catch (...) + { + throw Error("Invalid number '%s'", arg.c_str()); + } + }; + ratios.emplace(std::array{stof(ratios_str.substr(0, 2)), stof(ratios_str.substr(2, 2)), stof(ratios_str.substr(4, 2)), + stof(ratios_str.substr(6, 2))}); idt_alias = '(' + mixed_base + ')'; mixed_base = mixed_base[0]; } @@ -1491,7 +1501,14 @@ SequenceLoader::MonomerInfo SequenceLoader::readHelmMonomer(KetDocument& documen auto& opt = options.second.emplace_back(opt_alias, std::optional()); if (count.size() > 0) { - opt.second = std::stof(count); + try + { + opt.second = std::stof(count); + } + catch (...) + { + throw Error("Invalid number '%s'", count.c_str()); + } no_counts = false; } if (ch == ')')