Win32: support for UTF-16 surrogate pairs (ticket #457).
diff --git a/src/os/win32/ngx_files.c b/src/os/win32/ngx_files.c index c1c749e..32e28b5 100644 --- a/src/os/win32/ngx_files.c +++ b/src/os/win32/ngx_files.c
@@ -799,13 +799,25 @@ continue; } + if (u + 1 == last) { + *len = u - utf16; + break; + } + n = ngx_utf8_decode(&p, 4); - if (n > 0xffff) { + if (n > 0x10ffff) { ngx_set_errno(NGX_EILSEQ); return NULL; } + if (n > 0xffff) { + n -= 0x10000; + *u++ = (u_short) (0xd800 + (n >> 10)); + *u++ = (u_short) (0xdc00 + (n & 0x03ff)); + continue; + } + *u++ = (u_short) n; } @@ -838,12 +850,19 @@ n = ngx_utf8_decode(&p, 4); - if (n > 0xffff) { + if (n > 0x10ffff) { free(utf16); ngx_set_errno(NGX_EILSEQ); return NULL; } + if (n > 0xffff) { + n -= 0x10000; + *u++ = (u_short) (0xd800 + (n >> 10)); + *u++ = (u_short) (0xdc00 + (n & 0x03ff)); + continue; + } + *u++ = (u_short) n; }