delim = end;
if (str_begins(pos, "xn--", &value)) {
str_truncate(decoded, 0);
- if (punycode_decode(value, delim - value, result) < 0)
+ if (punycode_decode((const unsigned char *)value, delim - value, result) < 0)
/* Consider it as data */
str_append_data(result, pos, delim - pos + 1);
else if (*delim == '.')
}
/* Decodes a punycoded string into output, or returns -1 on error. */
-int punycode_decode(const char *input, size_t len, string_t *output)
+int punycode_decode(const unsigned char *input, size_t len, string_t *output)
{
ARRAY(unichar_t) label;
size_t i = 0;
size_t out = 0;
unsigned int n = initialN, bias = initialBias;
- const char *delim = NULL;
- const char *end = CONST_PTR_OFFSET(input, len);
- const char *ptr = input;
+ const unsigned char *delim = NULL;
+ const unsigned char *end = CONST_PTR_OFFSET(input, len);
+ const unsigned char *ptr = input;
t_array_init(&label, len);
/* find the rightmost delimiter, if present in string */
i_assert(delim <= end);
for (ptr = input; ptr < delim; ptr++) {
- if ((unsigned char)*ptr >= 0x80)
+ if (*ptr >= 0x80)
/* Has non-ascii input, this cannot be punycoded. */
return -1;
i_assert(out < sizeof(label));
/* Add basic code points to label */
- unichar_t ch = (unsigned char)*ptr;
+ unichar_t ch = *ptr;
array_push_back(&label, &ch);
}
/* Parse input as a punycode-encoded string and append it to
output. Returns 0 on success and -1 on failure. */
-int punycode_decode(const char *input, size_t len, string_t *output);
+int punycode_decode(const unsigned char *input, size_t len, string_t *output);
#endif
test_begin("punycode decoding");
for (i = 0; i < N_ELEMENTS(cases); i ++) {
str_truncate(r, 0);
- int ret = punycode_decode(cases[i].in, strlen(cases[i].in), r);
+ int ret = punycode_decode((const unsigned char *)cases[i].in, strlen(cases[i].in), r);
test_assert_idx(ret == cases[i].ret, i);
test_assert_strcmp_idx(str_c(r), cases[i].out, i);
}