[totem-pl-parser/wip/hadess/fix-xml-trailing-space: 2/3] core: Ignore trailing spaces in element names




commit bc05c00f84d0c709f179478c968c1bab26f62a23
Author: Bastien Nocera <hadess hadess net>
Date:   Tue Mar 2 12:37:16 2021 +0100

    core: Ignore trailing spaces in element names
    
    Closes: #28

 plparse/xmlparser.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
---
diff --git a/plparse/xmlparser.c b/plparse/xmlparser.c
index 3015960..a2da15c 100644
--- a/plparse/xmlparser.c
+++ b/plparse/xmlparser.c
@@ -273,6 +273,13 @@ static xml_node_t *xml_parser_append_text (xml_node_t *node, xml_node_t *subnode
 
 #define Q_STATE(CURRENT,NEW) (STATE_##NEW + state - STATE_##CURRENT)
 
+static int is_space(const char *str)
+{
+  char *text = str;
+  while (isspace (*text))
+    ++text;
+  return (*text == '\0');
+}
 
 static int xml_parser_get_node_internal (xml_parser_t *xml_parser,
                                 char ** token_buffer, int * token_buffer_size,
@@ -530,8 +537,10 @@ static int xml_parser_get_node_internal (xml_parser_t *xml_parser,
          return retval;
          break;
        default:
-         lprintf("error: unexpected token \"%s\", state %s (%d)\n", tok, state_to_str(state), state);
-         return -1;
+         if (!is_space(tok)) {
+           lprintf("error: unexpected token \"%s\", state %s (%d)\n", tok, state_to_str(state), state);
+           return -1;
+         }
          break;
        }
        break;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]