From 04dd07ab82e8af604fe66df7bc92e59d45c0c916 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 27 Feb 2016 10:03:45 +1300 Subject: Handle empty values in parser --- src/org/traccar/helper/Parser.java | 3 ++- test/org/traccar/protocol/XexunProtocolDecoderTest.java | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/org/traccar/helper/Parser.java b/src/org/traccar/helper/Parser.java index 73713c51c..dcea1c8f7 100644 --- a/src/org/traccar/helper/Parser.java +++ b/src/org/traccar/helper/Parser.java @@ -46,7 +46,8 @@ public class Parser { } public boolean hasNext(int number) { - if (matcher.group(position) != null) { + String value = matcher.group(position); + if (value != null && !value.isEmpty()) { return true; } else { position += number; diff --git a/test/org/traccar/protocol/XexunProtocolDecoderTest.java b/test/org/traccar/protocol/XexunProtocolDecoderTest.java index 96560fd03..770c4071d 100644 --- a/test/org/traccar/protocol/XexunProtocolDecoderTest.java +++ b/test/org/traccar/protocol/XexunProtocolDecoderTest.java @@ -11,6 +11,9 @@ public class XexunProtocolDecoderTest extends ProtocolTest { XexunProtocolDecoder decoder = new XexunProtocolDecoder(new XexunProtocol(), false); + verifyPosition(decoder, text( + "GPRMC,215853.000,A,5304.9600,N,10.7907,E,1.43,80.67,250216,00,0000.0,A*47,F,,imei:351525018007873,")); + verifyPosition(decoder, text( "GPRMC,215853.000,A,5304.9600,N,6.7907,E,1.43,80.67,250216,00,0000.0,A*47,F,,imei:351525018007873,")); -- cgit v1.2.3