[latex3-commits] [git/LaTeX3-latex3-luaotfload] dev: Fallback for invalid UTF-8 (57345f2)

Marcel Fabian Krüger tex at 2krueger.de
Mon Aug 19 16:10:50 CEST 2019


Repository : https://github.com/latex3/luaotfload
On branch  : dev
Link       : https://github.com/latex3/luaotfload/commit/57345f2522bfabe07f22cb36891ef1fde2bdd8a1

>---------------------------------------------------------------

commit 57345f2522bfabe07f22cb36891ef1fde2bdd8a1
Author: Marcel Fabian Krüger <tex at 2krueger.de>
Date:   Mon Aug 19 16:07:25 2019 +0200

    Fallback for invalid UTF-8


>---------------------------------------------------------------

57345f2522bfabe07f22cb36891ef1fde2bdd8a1
 src/luaotfload-database.lua                          | 20 +++++++++++++++++---
 .../tex/latex-dev/luaotfload/luaotfload-database.lua | 20 +++++++++++++++++---
 2 files changed, 34 insertions(+), 6 deletions(-)

diff --git a/src/luaotfload-database.lua b/src/luaotfload-database.lua
index 43e27a3..63bc0f9 100644
--- a/src/luaotfload-database.lua
+++ b/src/luaotfload-database.lua
@@ -239,9 +239,15 @@ end
 
 --- string -> string
 
+local invalidchars = "[^%a%d]"
+
 local sanitize_fontname = function (str)
     if str ~= nil then
-        str = alphnum_only(casefold(str, true))
+        if utf8len(str) then
+            str = alphnum_only(casefold(str, true))
+        else
+            str = stringgsub(stringlower(str), invalidchars, "")
+        end
         return str
     end
     return nil
@@ -252,11 +258,19 @@ local sanitize_fontnames = function (rawnames)
     for category, namedata in next, rawnames do
 
         if type (namedata) == "string" then
-            result [category] = alphnum_only(casefold(namedata, true))
+            if utf8len(namedata) then
+                result [category] = alphnum_only(casefold(namedata, true))
+            else
+                result [category] = stringgsub(stringlower(namedata), invalidchars, "")
+            end
         else
             local target = { }
             for field, name in next, namedata do
-                target [field] = alphnum_only(casefold(name, true))
+                if utf8len(name) then
+                    target [category] = alphnum_only(casefold(name, true))
+                else
+                    target [category] = stringgsub(stringlower(name), invalidchars, "")
+                end
             end
             result [category] = target
         end
diff --git a/texmf/tex/latex-dev/luaotfload/luaotfload-database.lua b/texmf/tex/latex-dev/luaotfload/luaotfload-database.lua
index 43e27a3..63bc0f9 100644
--- a/texmf/tex/latex-dev/luaotfload/luaotfload-database.lua
+++ b/texmf/tex/latex-dev/luaotfload/luaotfload-database.lua
@@ -239,9 +239,15 @@ end
 
 --- string -> string
 
+local invalidchars = "[^%a%d]"
+
 local sanitize_fontname = function (str)
     if str ~= nil then
-        str = alphnum_only(casefold(str, true))
+        if utf8len(str) then
+            str = alphnum_only(casefold(str, true))
+        else
+            str = stringgsub(stringlower(str), invalidchars, "")
+        end
         return str
     end
     return nil
@@ -252,11 +258,19 @@ local sanitize_fontnames = function (rawnames)
     for category, namedata in next, rawnames do
 
         if type (namedata) == "string" then
-            result [category] = alphnum_only(casefold(namedata, true))
+            if utf8len(namedata) then
+                result [category] = alphnum_only(casefold(namedata, true))
+            else
+                result [category] = stringgsub(stringlower(namedata), invalidchars, "")
+            end
         else
             local target = { }
             for field, name in next, namedata do
-                target [field] = alphnum_only(casefold(name, true))
+                if utf8len(name) then
+                    target [category] = alphnum_only(casefold(name, true))
+                else
+                    target [category] = stringgsub(stringlower(name), invalidchars, "")
+                end
             end
             result [category] = target
         end





More information about the latex3-commits mailing list