mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Complete - task : ALF-2904 Meeting Workspace with wildcards is displayed incorrectly. SP workspace creation failing because shortname not javascript escaped before submission - now correctly escaped. Calendar event information being lost due to incorrect splitting of iCal lines.
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@40978 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -227,6 +227,48 @@ public class CalendarTimezoneHelper
|
|||||||
return new int[] {month, dayOfMonth, dayOfWeek};
|
return new int[] {month, dayOfMonth, dayOfWeek};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Splits an iCal line into key and value by the first
|
||||||
|
* unquoted colon.
|
||||||
|
* @param icalLine
|
||||||
|
*/
|
||||||
|
protected static String[] icalLineKeyValue(String icalLine){
|
||||||
|
int delim = indexOfFirstUnquotedColon(icalLine);
|
||||||
|
if(delim == -1){
|
||||||
|
return new String[]{"",""};
|
||||||
|
}
|
||||||
|
String key = icalLine.substring(0,delim);
|
||||||
|
String value = icalLine.substring(delim+1);
|
||||||
|
return new String[]{key,value};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param icalLine
|
||||||
|
* @return location of first non quote enclosed colon
|
||||||
|
*/
|
||||||
|
private static int indexOfFirstUnquotedColon(String icalLine){
|
||||||
|
int colon = icalLine.indexOf(":");
|
||||||
|
int quote = icalLine.indexOf("\"");
|
||||||
|
|
||||||
|
if(quote == -1){
|
||||||
|
return colon;
|
||||||
|
}else{
|
||||||
|
if(colon<quote){
|
||||||
|
return colon;
|
||||||
|
}else{
|
||||||
|
//next quote, skipping past a colon if exists
|
||||||
|
int nextQuote = icalLine.indexOf("\"", quote+1);
|
||||||
|
if(nextQuote==-1){
|
||||||
|
//will only happen if the quotes are unbalanced
|
||||||
|
return -1;
|
||||||
|
}else{
|
||||||
|
return nextQuote + indexOfFirstUnquotedColon(icalLine.substring(nextQuote+1, icalLine.length())) + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Turns an iCal event into event + timezone parameters.
|
* Turns an iCal event into event + timezone parameters.
|
||||||
* This is very closely tied to the SPP / VTI implementation,
|
* This is very closely tied to the SPP / VTI implementation,
|
||||||
@@ -250,7 +292,7 @@ public class CalendarTimezoneHelper
|
|||||||
Stack<String> stack = new Stack<String>();
|
Stack<String> stack = new Stack<String>();
|
||||||
for (String line : segregatedLines)
|
for (String line : segregatedLines)
|
||||||
{
|
{
|
||||||
String[] keyValue = line.split(":");
|
String[] keyValue = icalLineKeyValue(line);
|
||||||
if (keyValue.length >= 2)
|
if (keyValue.length >= 2)
|
||||||
{
|
{
|
||||||
if (keyValue[0].equals("BEGIN"))
|
if (keyValue[0].equals("BEGIN"))
|
||||||
|
@@ -0,0 +1,53 @@
|
|||||||
|
package org.alfresco.service.cmr.calendar;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class CalendarTimezoneHelperTest {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ensure that iCal lines are split into key and value
|
||||||
|
* by the first unquoted colon
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void icalLineKeyValue(){
|
||||||
|
|
||||||
|
//blank line
|
||||||
|
String icalLine = "";
|
||||||
|
String[] keyVal = CalendarTimezoneHelper.icalLineKeyValue(icalLine);
|
||||||
|
assertEquals("", keyVal[0]);
|
||||||
|
assertEquals("", keyVal[1]);
|
||||||
|
|
||||||
|
//single unquoted
|
||||||
|
icalLine = "a:b";
|
||||||
|
keyVal = CalendarTimezoneHelper.icalLineKeyValue(icalLine);
|
||||||
|
assertEquals("a", keyVal[0]);
|
||||||
|
assertEquals("b", keyVal[1]);
|
||||||
|
|
||||||
|
//multiple unquoted colons
|
||||||
|
icalLine = "a:bcd:ds";
|
||||||
|
keyVal = CalendarTimezoneHelper.icalLineKeyValue(icalLine);
|
||||||
|
assertEquals("a", keyVal[0]);
|
||||||
|
assertEquals("bcd:ds", keyVal[1]);
|
||||||
|
|
||||||
|
//deliminating colon preceded by quoted colon
|
||||||
|
icalLine = "a\":bcdA\":ds";
|
||||||
|
keyVal = CalendarTimezoneHelper.icalLineKeyValue(icalLine);
|
||||||
|
assertEquals("a\":bcdA\"", keyVal[0]);
|
||||||
|
assertEquals("ds", keyVal[1]);
|
||||||
|
|
||||||
|
//deliminating colon preceded and followed by quoted colons
|
||||||
|
icalLine = "a\":bcdA\":ds\"hello\"";
|
||||||
|
keyVal = CalendarTimezoneHelper.icalLineKeyValue(icalLine);
|
||||||
|
assertEquals("a\":bcdA\"", keyVal[0]);
|
||||||
|
assertEquals("ds\"hello\"", keyVal[1]);
|
||||||
|
|
||||||
|
//unbalanced quotes
|
||||||
|
icalLine = "a\":bcdA:ds";
|
||||||
|
keyVal = CalendarTimezoneHelper.icalLineKeyValue(icalLine);
|
||||||
|
assertEquals("", keyVal[0]);
|
||||||
|
assertEquals("", keyVal[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user