[latex3-commits] [git/LaTeX3-latex3-luaotfload] master: Fallback for invalid UTF-8 (976e691)

Marcel Fabian Krüger tex at 2krueger.de
Mon Aug 19 17:20:33 CEST 2019


Repository : https://github.com/latex3/luaotfload
On branch  : master
Link       : https://github.com/latex3/luaotfload/commit/976e6911bd2d26d5ceab617895548dd0a88a1115

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

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

    Fallback for invalid UTF-8
    
    (cherry picked from 57345f2522bfabe07f22cb36891ef1fde2bdd8a1)
    (cherry picked from 1e6cb083cf4cc8bf8bdbef33ce73a6d7a276ec85)


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

976e6911bd2d26d5ceab617895548dd0a88a1115
 src/luaotfload-database.lua                         | 20 +++++++++++++++++---
 texmf/tex/luatex/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 0cff8f5..5365dd1 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 [field] = alphnum_only(casefold(name, true))
+                else
+                    target [field] = stringgsub(stringlower(name), invalidchars, "")
+                end
             end
             result [category] = target
         end
diff --git a/texmf/tex/luatex/luaotfload/luaotfload-database.lua b/texmf/tex/luatex/luaotfload/luaotfload-database.lua
index 0cff8f5..5365dd1 100644
--- a/texmf/tex/luatex/luaotfload/luaotfload-database.lua
+++ b/texmf/tex/luatex/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 [field] = alphnum_only(casefold(name, true))
+                else
+                    target [field] = stringgsub(stringlower(name), invalidchars, "")
+                end
             end
             result [category] = target
         end





More information about the latex3-commits mailing list