Project

General

Profile

Bug #266 ยป uri_escape.diff

patch to fix bug #266 -- iclaymore - Anonymous, 2005-11-05 15:28

View differences:

mod_webdav.c 2005-11-05 23:21:06.000000000 +0800
970 970
}
971 971
#endif
972 972

  
973
static const char hex_chars[] = "0123456789abcdef";
974
static int buffer_append_string_uri_encoded(buffer *b, const char *s, size_t s_len) {
975
	unsigned char *ds, *d;
976
	size_t d_len;
977
	
978
	if (!s || !b) return -1;
979
	
980
	if (b->ptr[b->used - 1] != '\0') {
981
		SEGFAULT();
982
	}
983
	
984
	if (s_len == 0) return 0;
985
	
986
	/* count to-be-encoded-characters */
987
	for (ds = (unsigned char *)s, d_len = 0; *ds; ds++) {
988
		if (*ds < 32 || *ds > 126) {
989
			d_len += 3;
990
		} else {
991
			switch (*ds) {
992
			case '$':
993
			case '&':
994
			case '+':
995
			case ',':
996
			case ':':
997
			case ';':
998
			case '=':
999
			case '?':
1000
			case '@':
1001
			case ' ':
1002
			case '#':
1003
			case '%':
1004
			case '<':
1005
			case '>':
1006
			case '"':
1007
			case '\'':
1008
				d_len += 3;
1009
				break;
1010
			default:
1011
				d_len ++;
1012
				break;
1013
			}
1014
		}
1015
	}
1016
	
1017
	buffer_prepare_append(b, d_len);
1018
	
1019
	for (ds = (unsigned char *)s, d = (unsigned char *)b->ptr + b->used - 1, d_len = 0; *ds; ds++) {
1020
		if (*ds < 32 || *ds > 126) {
1021
			d[d_len++] = '%';
1022
			d[d_len++] = hex_chars[((*ds) >> 4) & 0x0F];
1023
			d[d_len++] = hex_chars[(*ds) & 0x0F];
1024
		} else {
1025
			switch (*ds) {
1026
			case '$':
1027
			case '&':
1028
			case '+':
1029
			case ',':
1030
			case ':':
1031
			case ';':
1032
			case '=':
1033
			case '?':
1034
			case '@':
1035
			case ' ':
1036
			case '#':
1037
			case '%':
1038
			case '<':
1039
			case '>':
1040
			case '"':
1041
			case '\'':
1042
				d[d_len++] = '%';
1043
				d[d_len++] = hex_chars[((*ds) >> 4) & 0x0F];
1044
				d[d_len++] = hex_chars[(*ds) & 0x0F];
1045
				break;
1046
			default:
1047
				d[d_len++] = *ds;
1048
				break;
1049
			}
1050
		}
1051
	}
1052
	
1053
	b->ptr[b->used + d_len - 1] = '\0';
1054
	
1055
	b->used += d_len;
1056
	
1057
	return 0;
1058
}
1059

  
973 1060
URIHANDLER_FUNC(mod_webdav_subrequest_handler) {
974 1061
	plugin_data *p = p_d;
975 1062
	buffer *b;
......
1111 1198
			buffer_append_string_buffer(b, con->uri.scheme);
1112 1199
			buffer_append_string(b,"://");
1113 1200
			buffer_append_string_buffer(b, con->uri.authority);
1114
			buffer_append_string_buffer(b, con->uri.path);
1201
			buffer_append_string_uri_encoded(b, CONST_BUF_LEN(con->uri.path));
1115 1202
			buffer_append_string(b,"</D:href>\n");
1116 1203

  
1117 1204
			if (!buffer_is_empty(prop_200)) {
......
1176 1263
					buffer_append_string_buffer(b, con->uri.scheme);
1177 1264
					buffer_append_string(b,"://");
1178 1265
					buffer_append_string_buffer(b, con->uri.authority);
1179
					buffer_append_string_buffer(b, d.rel_path);
1266
					buffer_append_string_uri_encoded(b, 
1267
						CONST_BUF_LEN(d.rel_path));
1180 1268
					buffer_append_string(b,"</D:href>\n");
1181 1269

  
1182 1270
					if (!buffer_is_empty(prop_200)) {
    (1-1/1)