Quellcode durchsuchen

Small improvements, but it still fails with the machine.config

svn path=/trunk/mono/; revision=66808
Miguel de Icaza vor 19 Jahren
Ursprung
Commit
2e4641e7ef
2 geänderte Dateien mit 48 neuen und 14 gelöschten Zeilen
  1. 27 14
      eglib/src/gmarkup.c
  2. 21 0
      eglib/test/markup.c

+ 27 - 14
eglib/src/gmarkup.c

@@ -50,7 +50,8 @@ typedef enum {
 	TEXT,
 	FLUSH_TEXT,
 	CLOSING_ELEMENT,
-	COMMENT
+	COMMENT,
+	SKIP_XML_DECLARATION
 } ParseState;
 
 struct _GMarkupParseContext {
@@ -117,7 +118,8 @@ parse_value (const char *p, const char *end, char **value, GError **error)
 		return end;
 	}
 	start = ++p;
-	for (++p; p < end && *p != '"'; p++)
+	for (; p < end && *p != '"'; p++)
+		;
 	if (p == end)
 		return end;
 	l = p - start;
@@ -151,7 +153,7 @@ parse_name (const char *p, const char *end, char **value)
 }
 
 static const char *
-parse_attributes (const char *p, const char *end, char ***names, char ***values, GError **error, int *full_stop)
+parse_attributes (const char *p, const char *end, char ***names, char ***values, GError **error, int *full_stop, int state)
 {
 	int nnames = 0;
 
@@ -164,6 +166,11 @@ parse_attributes (const char *p, const char *end, char ***names, char ***values,
 			*full_stop = 0;
 			return p; 
 		}
+		if (state == SKIP_XML_DECLARATION && *p == '?' && ((p+1) < end) && *(p+1) == '>'){
+			*full_stop = 0;
+			return p+1;
+		}
+		
 		if (*p == '/' && ((p+1) < end && *(p+1) == '>')){
 			*full_stop = 1;
 			return p+1;
@@ -244,13 +251,17 @@ g_markup_parse_context_parse (GMarkupParseContext *context,
 			if (c == ' ' || c == '\t' || c == '\f' || c == '\n')
 				continue;
 			if (c == '<'){
-				context->state = START_ELEMENT;
+				if (p+1 < end && p [1] == '?'){
+					context->state = SKIP_XML_DECLARATION;
+					p++;
+				} else
+					context->state = START_ELEMENT;
 				continue;
 			}
 			set_error ("Expected < to start the document");
 			goto fail;
 
-
+		case SKIP_XML_DECLARATION:
 		case START_ELEMENT: {
 			const char *element_start = p, *element_end;
 			char *ename = NULL;
@@ -289,7 +300,7 @@ g_markup_parse_context_parse (GMarkupParseContext *context,
 				set_error ("Unfinished element");
 				goto fail;
 			}
-			p = parse_attributes (p, end, &names, &values, error, &full_stop);
+			p = parse_attributes (p, end, &names, &values, error, &full_stop, context->state);
 			if (p == end){
 				if (names != NULL) {
 					g_strfreev (names);
@@ -306,12 +317,13 @@ g_markup_parse_context_parse (GMarkupParseContext *context,
 				goto fail;
 			strncpy (ename, element_start, l);
 			ename [l] = 0;
-			
-			if (context->parser.start_element != NULL)
-				context->parser.start_element (context, ename,
-							       (const gchar **) names,
-							       (const gchar **) values,
-							       context->user_data, error);
+
+			if (context->state == START_ELEMENT)
+				if (context->parser.start_element != NULL)
+					context->parser.start_element (context, ename,
+								       (const gchar **) names,
+								       (const gchar **) values,
+								       context->user_data, error);
 
 			if (names != NULL){
 				g_strfreev (names);
@@ -324,7 +336,7 @@ g_markup_parse_context_parse (GMarkupParseContext *context,
 			}
 			
 			if (full_stop){
-				if (context->parser.end_element != NULL){
+				if (context->parser.end_element != NULL &&  context->state == START_ELEMENT){
 					context->parser.end_element (context, ename, context->user_data, error);
 					if (error != NULL && *error != NULL){
 						free (ename);
@@ -361,7 +373,7 @@ g_markup_parse_context_parse (GMarkupParseContext *context,
 				p += 2;
 				break;
 			}
-
+			break;
 			
 		case FLUSH_TEXT:
 			if (context->parser.text != NULL){
@@ -387,6 +399,7 @@ g_markup_parse_context_parse (GMarkupParseContext *context,
 				set_error ("Too many closing tags, not enough open tags");
 				goto fail;
 			}
+			
 			text = current->data;
 			if (context->parser.end_element != NULL){
 				context->parser.end_element (context, text, context->user_data, error);

+ 21 - 0
eglib/test/markup.c

@@ -201,11 +201,32 @@ mcs_config (void)
 
 }
 
+RESULT
+xml_parse (void)
+{
+	return markup_test ("<?xml version=\"1.0\" encoding=\"utf-8\"?><a></a>");
+}
+
+RESULT
+machine_config (void)
+{
+	char *data;
+	gsize size;
+	
+	if (g_file_get_contents ("../../data/net_1_1/machine.config", &data, &size, NULL)){
+		return markup_test (data);
+	}
+	printf ("Ignoring this test\n");
+	return NULL;
+}
+
 static Test markup_tests [] = {
 	{"invalid_documents", invalid_documents},
 	{"good_documents", valid_documents},
 	{"mono_domain", mono_domain},
 	{"mcs_config", mcs_config},
+	{"xml_parse", xml_parse},
+	{"machine_config", machine_config},
 	{NULL, NULL}
 };