Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b360dcec authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Allow key-value pair without value for VVM SMS" into nyc-mr1-dev

parents f0a3dc10 7d61cd7d
Loading
Loading
Loading
Loading
+13 −3
Original line number Diff line number Diff line
@@ -88,11 +88,21 @@ public class VisualVoicemailSmsParser {
            if (entry.length() == 0) {
                continue;
            }
            String[] keyValue = entry.split("=");
            if (keyValue.length != 2) {
            // The format for a field is <key>=<value>.
            // As the OMTP spec both key and value are required, but in some cases carriers will
            // send an SMS with missing value, so only the presence of the key is enforced.
            // For example, an SMS for a voicemail from restricted number might have "s=" for the
            // sender field, instead of omitting the field.
            int separatorIndex = entry.indexOf("=");
            if (separatorIndex == -1 || separatorIndex == 0) {
                // No separator or no key.
                // For example "foo" or "=value".
                // A VVM SMS should have all of its' field valid.
                return null;
            }
            keyValues.putString(keyValue[0].trim(), keyValue[1].trim());
            String key = entry.substring(0, separatorIndex);
            String value = entry.substring(separatorIndex + 1);
            keyValues.putString(key, value);
        }

        return keyValues;
+15 −0
Original line number Diff line number Diff line
@@ -132,4 +132,19 @@ public class VisualVoicemailSmsParserTest extends TestCase {
                "//VVM:STATUS:key");
        assertNull(result);
    }

    @SmallTest
    public void testParsingFail_InvalidMissingKey() {
        WrappedMessageData result = VisualVoicemailSmsParser.parse("//VVM",
                "//VVM:STATUS:=value");
        assertNull(result);
    }

    @SmallTest
    public void testParsingFail_MissingValue() {
        WrappedMessageData result = VisualVoicemailSmsParser.parse("//VVM",
                "//VVM:STATUS:key=");
        assertEquals("STATUS", result.prefix);
        assertEquals("", result.fields.getString("key"));
    }
}