Clone in a terminal:
Commit 4199d35
Johan Mattsson - 2014-12-23T17:24:32+00:00
4199d35992f9fe060138c53a3862ff81ba7193adjohan.mattsson.m@gmail.com

Fix XML parser error (bug: 0000058)

Changed files (5)

Diff

diff --git a/libbirdfont/BirdFont.vala b/libbirdfont/BirdFont.valaindex f82521f..4e82dcb 100644--- a/libbirdfont/BirdFont.vala+++ b/libbirdfont/BirdFont.vala@@ -483,6 +483,8 @@ public class BirdFont { 		DefaultCharacterSet.get_characters_for_prefered_language ();  		HeadTable.init ();+		+		TestBirdFont.run_tests (); 	}  	public static void set_bundle_path (string path) {diff --git a/libbirdfont/TestBirdFont.vala b/libbirdfont/TestBirdFont.valaindex 69c9497..d4b405b 100644--- a/libbirdfont/TestBirdFont.vala+++ b/libbirdfont/TestBirdFont.vala@@ -50,7 +50,6 @@ class TestBirdFont : GLib.Object { 		test_cases = tests.get_test_functions ();
 		current_case = test_cases.first ();
 		test_cases_to_run = "All";
-		
 		from_command_line ();
 	}
 	
@@ -62,6 +61,12 @@ class TestBirdFont : GLib.Object { 		slow_test = s;
 	}
 	
+	public static void run_tests () {
+		TestBirdFont t = get_singleton ();
+		state = RUNNING;
+		t.run_all_tests ();
+	}
+	
 	public static TestBirdFont get_singleton () {
 		if (singleton == null) {
 			singleton = new TestBirdFont ();
@@ -105,7 +110,7 @@ class TestBirdFont : GLib.Object { 			if (st == "All" || st == "") {
 				return;
 			} else {
-				stderr.printf  (@"Run only test case \"$st\" \n");
+				stderr.printf  (@"Run test case \"$st\" \n");
 			}
 			
 			test_cases_to_run = st;
@@ -210,7 +215,7 @@ class TestBirdFont : GLib.Object { 					
 			has_failed = false;
 			has_skipped = false;
-
+			
 			if (test_cases_to_run != "All" && test_cases_to_run != test.name) {
 				has_skipped = true;
 			} else {
diff --git a/libbirdfont/TestCases.vala b/libbirdfont/TestCases.valaindex 02916ca..7a78b98 100644--- a/libbirdfont/TestCases.vala+++ b/libbirdfont/TestCases.vala@@ -12,6 +12,8 @@     Lesser General Public License for more details. */ +using Bird;+ namespace BirdFont {  /** All the things we want to test listed is here. */@@ -47,6 +49,7 @@ class TestCases { 		add (test_double_quadratic, "Double quadratic"); 		add (test_raster_path, "Raster path"); 		add (test_file_path, "File path");+		add (test_xml, "XML");  		add_bechmark (benchmark_stroke, "Stroke"); 	}@@ -1284,6 +1287,45 @@ class TestCases { 			warning (@"Wrong folder, $folder"); 		}	 	}+	+	static void test_xml () {+		Tag root;+		XmlParser parser;++		parser = new XmlParser ("""<g><g><g></g><g><g></g></g></g></g>""");	++		root = parser.get_root_tag ();+		print_tags (root);++		if (parser.validate ()) {+			root = parser.get_root_tag ();+			print_tags (root);+		} else {+			warning ("Invalid XML code.");+		}++	}++	static void print_tags (Tag tag) {+		print (tag.get_name ());+		print ("\n");+		print_attributes (tag);+		print (tag.get_content ());++		foreach (Tag t in tag) {+			print_tags (t);+		}+	}++	static void print_attributes (Tag tag) {+		Attributes attributes = tag.get_attributes ();+		foreach (Attribute attribute in attributes) {+			print ("\t");+			print (attribute.get_name ());+			print ("\n");+		}+	}+ }  }diff --git a/libbirdxml/Tag.vala b/libbirdxml/Tag.valaindex 0d4db62..733e17d 100644--- a/libbirdxml/Tag.vala+++ b/libbirdxml/Tag.vala@@ -253,8 +253,8 @@ public class Tag { 		int index = start; 		int slash_index = start; 		int previous_index;-		unichar c;-		int start_count = 0;+		unichar c, slash;+		int start_count = 1; 		 		if (name.length == 0) { 			error = true;@@ -265,14 +265,15 @@ public class Tag { 		while (true) { 			previous_index = index; 			if (!data.get_next_char (ref index, out c)) {+				warn (@"Unexpected end of file"); 				break; 			} 			 			if (c == '<') { 				slash_index = index;-				data.get_next_char (ref slash_index, out c);-				if (c == '/' && is_tag (name, slash_index)) {-					if (start_count == 0) {+				data.get_next_char (ref slash_index, out slash);+				if (slash == '/' && is_tag (name, slash_index)) {+					if (start_count == 1) { 						return previous_index; 					} else { 						start_count--;@@ -281,7 +282,7 @@ public class Tag { 						} 					} 				} else if (is_tag (name, index)) {-					start_count++;					+					start_count++; 				} 			} 		}@@ -306,7 +307,6 @@ public class Tag { 			} 		} 		-		 		if (data.get_next_char (ref data_index, out c_data)) { 			return c_data == '>' || c_data == ' ' || c_data == '\t'  				|| c_data == '\n' || c_data == '\r' || c_data == '/';diff --git a/libbirdxml/Xml.vala b/libbirdxml/Xml.valaindex 6704091..396f29f 100644--- a/libbirdxml/Xml.vala+++ b/libbirdxml/Xml.vala@@ -60,7 +60,7 @@ internal const int WARNINGS = 1;  * void print_attributes (Tag tag) {  * 	Attributes attributes = tag.get_attributes ();  * 	foreach (Attribute attribute in attributes) {- * 		print (attribute.get_name ()");+ * 		print (attribute.get_name ());  * 		print ("\n");  * 	}  * }

Contact

Email: johan.mattsson.m@gmail.com
Mastodon: typo.social/@birdfont
GitHub: johanmattssonm
LinkedIn: johan-mattsson-2ab324112