# HG changeset patch # User Kim Alvefur # Date 1746458097 -7200 # Node ID 7f6916088278d1e4eb707527f7d6f41b4ba6b6f0 # Parent f489738a713c9a06d9e2bae3ed58581194d30f76 util.jsonschema: Simplify retrieval of UTF-8 length function diff -r f489738a713c -r 7f6916088278 teal-src/prosody/util/jsonschema.tl --- a/teal-src/prosody/util/jsonschema.tl Sun Mar 30 16:47:13 2025 +0200 +++ b/teal-src/prosody/util/jsonschema.tl Mon May 05 17:14:57 2025 +0200 @@ -10,12 +10,8 @@ if not math.type then require "prosody.util.mathcompat" end - -local utf8_enc = rawget(_G, "utf8") or require"prosody.util.encodings".utf8; -local utf8_len = utf8_enc.len or function(s : string) : integer - local _, count = s:gsub("[%z\001-\127\194-\253][\128-\191]*", ""); - return count -end; +-- XXX util.encodings seems to count differently from the Lua builtin +local utf8_len = rawget(_G, "utf8") and utf8.len or require"prosody.util.encodings".utf8.length; local json = require "prosody.util.json" local null = json.null; diff -r f489738a713c -r 7f6916088278 util/jsonschema.lua --- a/util/jsonschema.lua Sun Mar 30 16:47:13 2025 +0200 +++ b/util/jsonschema.lua Mon May 05 17:14:57 2025 +0200 @@ -4,11 +4,7 @@ require("prosody.util.mathcompat") end -local utf8_enc = rawget(_G, "utf8") or require("prosody.util.encodings").utf8; -local utf8_len = utf8_enc.len or function(s) - local _, count = s:gsub("[%z\001-\127\194-\253][\128-\191]*", ""); - return count -end; +local utf8_len = rawget(_G, "utf8") and utf8.len or require("prosody.util.encodings").utf8.length; local json = require("prosody.util.json") local null = json.null;