From 09161ea84f8b7449daab5c08c0df5d2c5e95ba43 Mon Sep 17 00:00:00 2001 From: Botond Baranyi <botond.baranyi@ericsson.com> Date: Tue, 30 Oct 2018 15:51:24 +0100 Subject: [PATCH] Fixed XER list decoding with leading whitespaces (bug 540607) Change-Id: Ic3f574de0895accee746f960b1ba6705669527bf Signed-off-by: Botond Baranyi <botond.baranyi@ericsson.com> --- compiler2/record_of.c | 2 +- core2/Basetype2.cc | 2 +- .../XML/EXER-whitepaper/List.ttcnpp | 28 +++++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/compiler2/record_of.c b/compiler2/record_of.c index dfe66158e..7cee6d807 100644 --- a/compiler2/record_of.c +++ b/compiler2/record_of.c @@ -1404,7 +1404,7 @@ void defRecordOfClass1(const struct_of_def *sdef, output_struct *output) * then use that to decode the value. */ " for(char * str = strtok(x_val, \" \\t\\x0A\\x0D\"); str != 0; str = strtok(x_val + x_pos, \" \\t\\x0A\\x0D\")) {\n" // Calling strtok with NULL won't work here, since the decoded element can have strtok calls aswell - " x_pos += strlen(str) + 1;\n" + " x_pos = (str - x_val) + strlen(str) + 1;\n" " TTCN_Buffer buf_2;\n" " buf_2.put_c('<');\n" " write_ns_prefix(*p_td.oftype_descr, buf_2);\n" diff --git a/core2/Basetype2.cc b/core2/Basetype2.cc index fc4b0996c..f41a9fa43 100644 --- a/core2/Basetype2.cc +++ b/core2/Basetype2.cc @@ -2480,7 +2480,7 @@ int Record_Of_Type::XER_decode(const XERdescriptor_t& p_td, * to decode the value. */ for(char * str = strtok(val, " \t\x0A\x0D"); str != 0; str = strtok(val + pos, " \t\x0A\x0D")) { // Calling strtok with NULL won't work here, since the decoded element can have strtok calls aswell - pos += strlen(str) + 1; + pos = (str - val) + strlen(str) + 1; // Construct a new XML Reader with the current token. TTCN_Buffer buf2; const XERdescriptor_t& sub_xer = *p_td.oftype_descr; diff --git a/regression_test/XML/EXER-whitepaper/List.ttcnpp b/regression_test/XML/EXER-whitepaper/List.ttcnpp index de187c55b..f2938031f 100644 --- a/regression_test/XML/EXER-whitepaper/List.ttcnpp +++ b/regression_test/XML/EXER-whitepaper/List.ttcnpp @@ -7,6 +7,7 @@ * * Contributors: * Balasko, Jeno + * Baranyi, Botond * Raduly, Csaba * ******************************************************************************/ @@ -92,11 +93,38 @@ testcase decode_floats() runs on L /* * * * * * * * * * * * * * * * * * * * */ +// decoding a list with leading whitespaces (bug 540607) +type record of universal charstring Strings +with { + variant "list" +} + +DECLARE_EXER_ENCODERS(Strings, strings); + +const Strings str := { "first", "second", "third", "fourth" } + +const universal charstring str_dec := +"<Strings> + first + second + third + fourth + </Strings>"; + + +testcase decode_strings() runs on L +{ + CHECK_DECODE(exer_dec_strings, str_dec, Strings, str); +} + +/* * * * * * * * * * * * * * * * * * * * */ + control { execute(encode_ints()); execute(decode_ints()); execute(encode_floats()); execute(decode_floats()); + execute(decode_strings()); } } -- GitLab