Skip to content

Commit

Permalink
Fix loop when parsing broken gpx files
Browse files Browse the repository at this point in the history
  • Loading branch information
bailuk committed Nov 3, 2019
1 parent f13c0e2 commit 01d00a7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ private boolean begins(XmlPullParser parser) throws XmlPullParserException {
}

private boolean ends(XmlPullParser parser) throws XmlPullParserException {
return parser.getEventType() == XmlPullParser.END_TAG
&& (tag == null || Objects.equals(parser.getName(), tag));
return parser.getEventType() == XmlPullParser.END_DOCUMENT ||

(parser.getEventType() == XmlPullParser.END_TAG &&
(tag == null || Objects.equals(parser.getName(), tag)));
}


Expand Down
18 changes: 14 additions & 4 deletions app/src/main/java/ch/bailu/aat/gpx/xml_parser/parser/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,32 @@
import java.io.IOException;

import ch.bailu.aat.gpx.xml_parser.scanner.Scanner;
import ch.bailu.aat.util.ui.AppLog;
import ch.bailu.util_java.util.Objects;

public class Util {

/**
* Read until tag ends or document ends
*
* @param parser
* @throws IOException
* @throws XmlPullParserException
*/
public static void skipTag(XmlPullParser parser) throws IOException, XmlPullParserException {
String tag = parser.getName();
final String tag = parser.getName();

// log(parser);
while(tag != null) {
while (tag != null) {

int event = parser.next();

if (event == XmlPullParser.END_TAG
&& Objects.equals(tag, parser.getName())) {
// log(parser);
return;

} else if (event == XmlPullParser.END_DOCUMENT) {
return;

}
}
}
Expand Down

1 comment on commit 01d00a7

@bailuk
Copy link
Owner Author

@bailuk bailuk commented on 01d00a7 Nov 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably fixes #63

Please sign in to comment.