1
0
mirror of https://github.com/moparisthebest/davmail synced 2024-12-13 03:02:22 -05:00

DAV: Encode apos in urlcompname used in DAV search request

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1371 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2010-08-23 06:45:13 +00:00
parent 02d66e3b88
commit 3437b309d1
3 changed files with 16 additions and 4 deletions

View File

@ -767,7 +767,7 @@ public class DavExchangeSession extends ExchangeSession {
buffer.append('%');
}
if ("urlcompname".equals(field.alias)) {
buffer.append(StringUtil.encodeUrlcompname(value));
buffer.append(StringUtil.encodeUrlcompname(StringUtil.davSearchEncode(value)));
} else if (field.isIntValue()) {
// check value
try {
@ -778,7 +778,7 @@ public class DavExchangeSession extends ExchangeSession {
buffer.append('0');
}
} else {
buffer.append(value);
buffer.append(StringUtil.davSearchEncode(value));
}
if (Operator.Like == operator || Operator.StartsWith == operator) {
buffer.append('%');

View File

@ -142,6 +142,9 @@ public final class StringUtil {
private static final Pattern UNDERSCORE_PATTERN = Pattern.compile("_");
private static final Pattern DASH_PATTERN = Pattern.compile("-");
// WebDav search parameter encode
private static final Pattern APOS_PATTERN = Pattern.compile("'");
/**
* Encode & to %26 for urlcompname.
*
@ -302,4 +305,12 @@ public final class StringUtil {
}
return result;
}
public static String davSearchEncode(String value) {
String result = value;
if (result.indexOf('\'') >= 0) {
result = APOS_PATTERN.matcher(result).replaceAll("''");
}
return result;
}
}

View File

@ -445,7 +445,8 @@ public class TestExchangeSessionContact extends AbstractExchangeSessionTestCase
System.out.println(contact.getBody());
}
public void testSpecialCharacters() throws IOException {
public void testSpecialUrlCharacters() throws IOException {
testCreateFolder();
VCardWriter vCardWriter = new VCardWriter();
vCardWriter.startCard();
@ -453,7 +454,7 @@ public class TestExchangeSessionContact extends AbstractExchangeSessionTestCase
vCardWriter.appendProperty("FN", "common name");
vCardWriter.endCard();
itemName = "test & accentué.vcf";
itemName = "test {<:&'>+} accentué.vcf";
ExchangeSession.ItemResult result = session.createOrUpdateContact("testcontactfolder", itemName, vCardWriter.toString(), null, null);
assertEquals(201, result.status);