]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
girparser: Don't guess length of xml header, iterate forward to <repository>
authorRico Tzschichholz <ricotz@ubuntu.com>
Fri, 19 Mar 2021 15:00:49 +0000 (16:00 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Fri, 19 Mar 2021 15:00:49 +0000 (16:00 +0100)
If e.g. the xml header is missing, it resulted in errors like:

    error: expected start element of `repository'
    error: unsupported GIR version (null) (supported: 1.2)

vala/valagirparser.vala

index b1086b893bdac0e17b19cb87ac44c368b8d07428..2345c355e6ddba0ec271b80024009198e41f1f31 100644 (file)
@@ -1479,10 +1479,14 @@ public class Vala.GirParser : CodeVisitor {
                reader = new MarkupReader (source_file.filename);
 
                // xml prolog
-               next ();
-               next ();
+               do {
+                       next ();
+                       if (current_token == MarkupTokenType.EOF) {
+                               Report.error (get_current_src (), "unexpected end of file");
+                               return;
+                       }
+               } while (current_token != MarkupTokenType.START_ELEMENT && reader.name != "repository");
 
-               next ();
                parse_repository ();
 
                reader = null;