Merge "ICS Writer: Quote common name."

This commit is contained in:
Makoto Onuki 2010-03-15 12:59:40 -07:00 committed by Android (Google) Code Review
commit 90299163a3
3 changed files with 23 additions and 1 deletions

View File

@ -1392,7 +1392,7 @@ public class CalendarUtilities {
if ((messageFlag & Message.FLAG_OUTGOING_MEETING_REQUEST_MASK) != 0) { if ((messageFlag & Message.FLAG_OUTGOING_MEETING_REQUEST_MASK) != 0) {
String icalTag = ICALENDAR_ATTENDEE_INVITE; String icalTag = ICALENDAR_ATTENDEE_INVITE;
if (attendeeName != null) { if (attendeeName != null) {
icalTag += ";CN=" + attendeeName; icalTag += ";CN=" + SimpleIcsWriter.quoteParamValue(attendeeName);
} }
ics.writeTag(icalTag, "MAILTO:" + attendeeEmail); ics.writeTag(icalTag, "MAILTO:" + attendeeEmail);
toList.add(attendeeName == null ? new Address(attendeeEmail) : toList.add(attendeeName == null ? new Address(attendeeEmail) :

View File

@ -69,4 +69,17 @@ public class SimpleIcsWriter extends CharArrayWriter {
write(value); write(value);
newLine(); newLine();
} }
/**
* Quote a param-value string, according to RFC 5545, section 3.1
*/
public static String quoteParamValue(String paramValue) {
if (paramValue == null) {
return null;
}
// Wrap with double quotes. You can't put double-quotes itself in it, so remove them first.
// We can be smarter -- e.g. we don't have to wrap an empty string with dquotes -- but
// we don't have to.
return "\"" + paramValue.replace("\"", "") + "\"";
}
} }

View File

@ -65,4 +65,13 @@ public class SimpleIcsWriterTests extends TestCase {
assertEquals(SimpleIcsWriter.MAX_LINE_LENGTH + SimpleIcsWriter.LINE_BREAK_LENGTH + assertEquals(SimpleIcsWriter.MAX_LINE_LENGTH + SimpleIcsWriter.LINE_BREAK_LENGTH +
(SimpleIcsWriter.MAX_LINE_LENGTH - 1), str.indexOf(expectedSecondLineBreak)); (SimpleIcsWriter.MAX_LINE_LENGTH - 1), str.indexOf(expectedSecondLineBreak));
} }
public void testQuoteParamValue() {
assertNull(SimpleIcsWriter.quoteParamValue(null));
assertEquals("\"\"", SimpleIcsWriter.quoteParamValue(""));
assertEquals("\"a\"", SimpleIcsWriter.quoteParamValue("a"));
assertEquals("\"\"", SimpleIcsWriter.quoteParamValue("\""));
assertEquals("\"abc\"", SimpleIcsWriter.quoteParamValue("abc"));
assertEquals("\"abc\"", SimpleIcsWriter.quoteParamValue("a\"b\"c"));
}
} }