Solving a bug with no params but a child

This commit is contained in:
Tristan Roux
2019-12-06 10:55:41 +01:00
parent 5d4e415291
commit 767cf1f289
2 changed files with 13 additions and 11 deletions
+12 -9
View File
@@ -11,7 +11,7 @@
#include <stdlib.h>
#include <stdbool.h>
char *xml_getname(char **nodestr, bool *has_parameters)
char *xml_getname(char **nodestr, bool *has_parameters, bool *has_childs)
{
char *p = my_strchr(*nodestr, ' ');
char *name;
@@ -24,10 +24,13 @@ char *xml_getname(char **nodestr, bool *has_parameters)
} else {
*has_parameters = false;
p = my_strchr(*nodestr, '/');
if (!p)
if (!p) {
p = my_strchr(*nodestr, '>');
else
*has_childs = true;
} else {
i++;
*has_childs = false;
}
if (p)
*p = '\0';
else
@@ -129,24 +132,24 @@ int xml_parsechild(node *n, char **nodestr, bool has_child)
node *xml_parsenode(char **nodestr)
{
node *n = malloc(sizeof(node));
bool has_next_value;
bool has_params;
bool has_childs;
char *p = my_strchr(*nodestr, '>');
if (!n || !p || (*nodestr)[0] != '<' || (*nodestr)[1] == '/')
return (NULL);
*p = '\0';
n->name = xml_getname(nodestr, &has_next_value);
n->name = xml_getname(nodestr, &has_params, &has_childs);
if (!n->name)
return (NULL);
//IF THE NODE HAS NO PARAMTERS BUT A CHILD, THE SYSTEM TELLS THAT IT HAS NETHER. HERE CHILDS ARE USED ONLY WHEN THE NODE AS PARAMS
if (has_next_value) {
n->properties = xml_getproperties(nodestr, &has_next_value);
if (has_params) {
n->properties = xml_getproperties(nodestr, &has_childs);
if (!n->properties)
return (NULL);
}
else
n->properties = NULL;
if (xml_parsechild(n, nodestr, has_next_value) < 0)
if (xml_parsechild(n, nodestr, has_childs) < 0)
return (NULL);
return (n);
}
+1 -2
View File
@@ -55,9 +55,8 @@ Test(xml, withchild)
node *n = xml_parsenode(&xml);
cr_assert_str_eq(n->name, "yes");
cr_assert_eq(n->next, NULL);
cr_expect_eq(n->next, NULL);
cr_assert_eq(n->properties, NULL);
cr_assert_eq(n->properties->next, NULL);
cr_assert_str_eq(n->child->name, "nop");
cr_assert_eq(n->child->child, NULL);
cr_assert_eq(n->child->properties, NULL);