1
0
mirror of https://github.com/moparisthebest/davmail synced 2025-01-07 03:38:05 -05:00

Caldav: encode ? in urlcompname

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1974 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2012-07-06 22:25:48 +00:00
parent 341eda2789
commit 435707181c
2 changed files with 20 additions and 0 deletions

View File

@ -151,6 +151,7 @@ public final class StringUtil {
private static final Pattern URLENCODED_HASH_PATTERN = Pattern.compile("%23"); private static final Pattern URLENCODED_HASH_PATTERN = Pattern.compile("%23");
private static final Pattern URLENCODED_STAR_PATTERN = Pattern.compile("%2A"); private static final Pattern URLENCODED_STAR_PATTERN = Pattern.compile("%2A");
private static final Pattern URLENCODED_PIPE_PATTERN = Pattern.compile("%7C"); private static final Pattern URLENCODED_PIPE_PATTERN = Pattern.compile("%7C");
private static final Pattern URLENCODED_QUESTION_PATTERN = Pattern.compile("%3F");
private static final Pattern ENCODED_AMP_PATTERN = Pattern.compile("&"); private static final Pattern ENCODED_AMP_PATTERN = Pattern.compile("&");
private static final Pattern ENCODED_LT_PATTERN = Pattern.compile("<"); private static final Pattern ENCODED_LT_PATTERN = Pattern.compile("<");
@ -165,6 +166,7 @@ public final class StringUtil {
private static final Pattern UNDERSCORE_PATTERN = Pattern.compile("_"); private static final Pattern UNDERSCORE_PATTERN = Pattern.compile("_");
private static final Pattern DASH_PATTERN = Pattern.compile("-"); private static final Pattern DASH_PATTERN = Pattern.compile("-");
private static final Pattern PIPE_PATTERN = Pattern.compile("\\|"); private static final Pattern PIPE_PATTERN = Pattern.compile("\\|");
private static final Pattern QUESTION_PATTERN = Pattern.compile("\\?");
// WebDav search parameter encode // WebDav search parameter encode
private static final Pattern APOS_PATTERN = Pattern.compile("'"); private static final Pattern APOS_PATTERN = Pattern.compile("'");
@ -334,6 +336,9 @@ public final class StringUtil {
if (result.indexOf('|') >= 0) { if (result.indexOf('|') >= 0) {
result = PIPE_PATTERN.matcher(result).replaceAll("%7C"); result = PIPE_PATTERN.matcher(result).replaceAll("%7C");
} }
if (result.indexOf('?') >= 0) {
result = QUESTION_PATTERN.matcher(result).replaceAll("%3F");
}
return result; return result;
} }
@ -380,6 +385,9 @@ public final class StringUtil {
if (result.indexOf("%7C") >= 0) { if (result.indexOf("%7C") >= 0) {
result = URLENCODED_PIPE_PATTERN.matcher(result).replaceAll("|"); result = URLENCODED_PIPE_PATTERN.matcher(result).replaceAll("|");
} }
if (result.indexOf("%3F") >= 0) {
result = URLENCODED_QUESTION_PATTERN.matcher(result).replaceAll("?");
}
// last replace % // last replace %
if (result.indexOf("%25") >= 0) { if (result.indexOf("%25") >= 0) {
result = URLENCODED_PERCENT_PATTERN.matcher(result).replaceAll("%"); result = URLENCODED_PERCENT_PATTERN.matcher(result).replaceAll("%");

View File

@ -19,6 +19,8 @@
package davmail.util; package davmail.util;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.commons.httpclient.URIException;
import org.apache.commons.httpclient.util.URIUtil;
/** /**
* Test StringUtil. * Test StringUtil.
@ -107,4 +109,14 @@ public class StringUtilTest extends TestCase {
assertEquals("test %7C", StringUtil.encodeUrlcompname("test |")); assertEquals("test %7C", StringUtil.encodeUrlcompname("test |"));
assertEquals("test |", StringUtil.decodeUrlcompname("test %7C")); assertEquals("test |", StringUtil.decodeUrlcompname("test %7C"));
} }
public void testEncodeQuestion() {
try {
URIUtil.encodeWithinQuery("test ?");
} catch (URIException e) {
e.printStackTrace();
}
assertEquals("test %3F", StringUtil.encodeUrlcompname("test ?"));
assertEquals("test ?", StringUtil.decodeUrlcompname("test %3F"));
}
} }