From a7c460b6d7a88a47ab389ac5f45b9ed7b801342d Mon Sep 17 00:00:00 2001 From: Thomas Harning Jr Date: Mon, 28 Sep 2015 14:21:14 -0400 Subject: [PATCH] test: update utf-8 handler to be more strict about integer division --- tests/utf8_processor.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/utf8_processor.lua b/tests/utf8_processor.lua index 76b5590..88f22b6 100644 --- a/tests/utf8_processor.lua +++ b/tests/utf8_processor.lua @@ -2,6 +2,8 @@ local lpeg = require("lpeg") local string = string +local floor = require("math").floor + local _ENV = nil local function encode_utf(codepoint) @@ -10,7 +12,7 @@ local function encode_utf(codepoint) elseif codepoint > 0xFFFF then -- Surrogate pair needed codepoint = codepoint - 0x10000 - local first, second = codepoint / 0x0400 + 0xD800, codepoint % 0x0400 + 0xDC00 + local first, second = floor(codepoint / 0x0400) + 0xD800, codepoint % 0x0400 + 0xDC00 return ("\\u%.4X\\u%.4X"):format(first, second) else return ("\\u%.4X"):format(codepoint) -- 2.11.4.GIT