| 228 |
228 |
| 229 |
229 |
| 230 /* --------------------------- util_uri_escape ---------------------------- */ |
230 /* --------------------------- util_uri_escape ---------------------------- */ |
| 231 NSAPI_PUBLIC char *util_uri_escape(char *od, const char *s) |
231 NSAPI_PUBLIC char *util_uri_escape(char *od, const char *s) |
| 232 { |
232 { |
| 233 int flagDbcsUri = allow_dbcs_uri(); |
233 size_t len = (strlen(s)*3) + 1; |
| 234 char *d; |
|
| 235 |
|
| 236 if (!od) |
234 if (!od) |
| 237 od = (char *) MALLOC((strlen(s)*3) + 1); |
235 od = (char *) MALLOC(len); |
| 238 d = od; |
236 |
| 239 |
237 util_uri_escape_s(od, len, s); |
| 240 while (*s) { |
238 |
| 241 if (strchr("% ?#:+&*\"'<>\r\n", *s)) { |
|
| 242 util_sprintf(d, "%%%02x", (unsigned char)*s); |
|
| 243 ++s; d += 3; |
|
| 244 } |
|
| 245 #ifdef XP_WIN32 |
|
| 246 else if (flagDbcsUri && s[1] && IsDBCSLeadByte(s[0])) |
|
| 247 #else |
|
| 248 // Treat any character with the high bit set as a DBCS lead byte |
|
| 249 else if (flagDbcsUri && s[1] && (s[0] & 0x80)) |
|
| 250 #endif |
|
| 251 { |
|
| 252 // Escape the second byte of DBCS characters. The first byte will |
|
| 253 // have been escaped already. IE translates all unescaped '\\'s |
|
| 254 // into '/'. |
|
| 255 // Bug 353999 |
|
| 256 util_sprintf(d, "%%%02x%%%02x", (unsigned char)s[0], (unsigned char)s[1]); |
|
| 257 s += 2; d += 6; |
|
| 258 } |
|
| 259 else if (0x80 & *s) { |
|
| 260 util_sprintf(d, "%%%02x", (unsigned char)*s); |
|
| 261 ++s; d += 3; |
|
| 262 } else { |
|
| 263 *d++ = *s++; |
|
| 264 } |
|
| 265 } |
|
| 266 *d = '\0'; |
|
| 267 return od; |
239 return od; |
| 268 } |
240 } |
| 269 |
241 |
| 270 NSAPI_PUBLIC size_t util_uri_escape_s(char *buf, size_t len, const char *s) { |
242 NSAPI_PUBLIC size_t util_uri_escape_s(char *buf, size_t len, const char *s) { |
| 271 char *d = buf; |
243 char *d = buf; |