# HG changeset patch # User Maxim Dounin # Date 1388791935 -14400 # Node ID 1cd23ca84a9bbaa965160dba5ba62bda3e8a9e32 # Parent 6a3ab6fdd70f9c57e51cc0e1ee2b1cfff2d39e7e 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 --- a/src/os/win32/ngx_files.c +++ b/src/os/win32/ngx_files.c @@ -799,11 +799,23 @@ ngx_utf8_to_utf16(u_short *utf16, u_char continue; } + if (u + 1 == last) { + *len = u - utf16; + break; + } + n = ngx_utf8_decode(&p, 4); + if (n > 0x10ffff) { + ngx_set_errno(NGX_EILSEQ); + return NULL; + } + if (n > 0xffff) { - ngx_set_errno(NGX_EILSEQ); - return NULL; + n -= 0x10000; + *u++ = (u_short) (0xd800 + (n >> 10)); + *u++ = (u_short) (0xdc00 + (n & 0x03ff)); + continue; } *u++ = (u_short) n; @@ -838,12 +850,19 @@ ngx_utf8_to_utf16(u_short *utf16, u_char 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; }