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

Commit 7d61cd7d authored by Ta-wei Yen's avatar Ta-wei Yen
Browse files

Allow key-value pair without value for VVM SMS

While a field doesn't have a value the field should not be sent, but
some carrier ignores this specification.

This CL relaxes the constraint on key-value pairs.

Change-Id: Ic3f8b4ff538447fb2aec6aa0107015f8c3fd0808
Fixes: 30124301
parent 0f6c2788
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"));
    }
}