Skip to content

Commit be184b3

Browse files
zaoWires77
andauthored
Fix fallout from SimpleGraphic upgrade with wider Unicode support (PathOfBuildingCommunity#8412)
* fix: enable Unicode separators and caret motions As the runtime is going to support Unicode installation locations and build directories, some UTF-8 text is going to reach the Lua side of the project. This includes the script path, the user path, any paths yielded from file searches and also imported character names from accounts. Care needs to be taken in many places where string operations are performed as no longer does a byte necessarily correspond to a single character and anything that truncates, reverses or otherwise slices strings could need an audit. This change fixes cursor movement in `EditControl`s with the arrow keys as those historically used string matching and byte offsets. It also ensures that the use of arbitrary Unicode codepoints as decimal and thousands separators works correctly as the previous code used unaware reversing and slicing. * fix: turn update paths relative for wide installs The updater is a fixed piece of older code that uses a Lua runtime that only handles paths that are representable in the user's text codepage. As the software may be installed in a location that cannot be expressed in that way, to mitigate the problem we turn all the paths in the update op-files into relative paths. That way as long as we never use exotic codepoints in our own paths it should be able to apply them cleanly and restart Path of Building afterward with a relative path. The updater executable can ironically enough not be updated at all with the related type of runtime hacks we introduced in SimpleGraphic as the updater deadlocks in updating itself. We have to work around its shortcomings in how we produce the op-files and possibly the update application script that runs under that limited runtime. * fix: convert GIFs masquerading as PNG to PNG Upon removing support for several file formats like GIF and BLP from the SimpleGraphic runtime, we noticed that there were some assets that had incorrect file extensions and loaded only thanks to file format detection ignoring extensions. As the actual file format loader for GIF was removed, these stealth GIFs are now losslessly converted to PNG. * Add luautf8 to Dockerfile --------- Co-authored-by: Wires77 <[email protected]>
1 parent 7199e04 commit be184b3

File tree

6 files changed

+19
-31
lines changed

6 files changed

+19
-31
lines changed

Dockerfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ RUN --mount=type=cache,from=luarocks,source=/opt,target=/opt make -C /opt/luaroc
3131
# Install here to install lua rocks pkgs in pararell with compilation of emmylua and luajit
3232
RUN luarocks install busted 2.2.0-1;\
3333
luarocks install cluacov 0.1.2-1;\
34-
luarocks install luacov-coveralls 0.2.3-1
34+
luarocks install luacov-coveralls 0.2.3-1;\
35+
luarocks install luautf8 0.1.6-1
3536

3637
RUN --mount=type=cache,from=emmyluadebugger,source=/opt,target=/opt make -C /opt/EmmyLuaDebugger/build/ install
3738
RUN --mount=type=cache,from=luajit,source=/opt,target=/opt make -C /opt/LuaJIT/ install

src/Classes/EditControl.lua

+8-23
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ local m_max = math.max
77
local m_min = math.min
88
local m_floor = math.floor
99
local protected_replace = "*"
10+
local utf8 = require('lua-utf8')
1011

1112
local function lastLine(str)
1213
local lastLineIndex = 1
@@ -541,18 +542,10 @@ function EditClass:OnKeyDown(key, doubleClick)
541542
if self.caret > 1 then
542543
if ctrl then
543544
-- Skip leading space, then jump word
544-
while self.buf:sub(self.caret-1, self.caret-1):match("[%s%p]") do
545-
if self.caret > 1 then
546-
self.caret = self.caret - 1
547-
end
548-
end
549-
while self.buf:sub(self.caret-1, self.caret-1):match("%w") do
550-
if self.caret > 1 then
551-
self.caret = self.caret - 1
552-
end
553-
end
545+
self.caret = self.caret - #utf8.match(self.buf:sub(1, self.caret-1), "[%s%p]*$")
546+
self.caret = self.caret - #utf8.match(self.buf:sub(1, self.caret-1), "%w*$")
554547
else
555-
self.caret = self.caret - 1
548+
self.caret = utf8.next(self.buf, self.caret, -1) or 0
556549
end
557550
self.lastUndoState.caret = self.caret
558551
self:ScrollCaretIntoView()
@@ -562,19 +555,11 @@ function EditClass:OnKeyDown(key, doubleClick)
562555
self.sel = shift and (self.sel or self.caret) or nil
563556
if self.caret <= #self.buf then
564557
if ctrl then
565-
-- Jump word, then skip trailing space,
566-
while self.buf:sub(self.caret, self.caret):match("%w") do
567-
if self.caret <= #self.buf then
568-
self.caret = self.caret + 1
569-
end
570-
end
571-
while self.buf:sub(self.caret, self.caret):match("[%s%p]") do
572-
if self.caret <= #self.buf then
573-
self.caret = self.caret + 1
574-
end
575-
end
558+
-- Jump word, then skip trailing space,
559+
self.caret = self.caret + #utf8.match(self.buf:sub(self.caret), "^%w*")
560+
self.caret = self.caret + #utf8.match(self.buf:sub(self.caret), "^[%s%p]*")
576561
else
577-
self.caret = self.caret + 1
562+
self.caret = utf8.next(self.buf, self.caret, 1) or #self.buf + 1
578563
end
579564
self.lastUndoState.caret = self.caret
580565
self:ScrollCaretIntoView()

src/Modules/Common.lua

+7-5
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ common.curl = require("lcurl.safe")
2626
common.xml = require("xml")
2727
common.base64 = require("base64")
2828
common.sha1 = require("sha1")
29+
local utf8 = require('lua-utf8')
2930

3031
-- Try to load a library return nil if failed. https://stackoverflow.com/questions/34965863/lua-require-fallback-error-handling
3132
function prerequire(...)
@@ -657,20 +658,21 @@ function formatNumSep(str)
657658
end
658659
local x, y, minus, integer, fraction = str:find("(-?)(%d+)(%.?%d*)")
659660
if main.showThousandsSeparators then
660-
integer = integer:reverse():gsub("(%d%d%d)", "%1"..main.thousandsSeparator):reverse()
661+
rev1kSep = utf8.reverse(main.thousandsSeparator)
662+
integer = utf8.reverse(utf8.gsub(utf8.reverse(integer), "(%d%d%d)", "%1"..rev1kSep))
661663
-- There will be leading separators if the number of digits are divisible by 3
662664
-- This checks for their presence and removes them
663665
-- Don't use patterns here because thousandsSeparator can be a pattern control character, and will crash if used
664666
if main.thousandsSeparator ~= "" then
665-
local thousandsSeparator = string.find(integer, main.thousandsSeparator, 1, 2)
667+
local thousandsSeparator = utf8.find(integer, rev1kSep, 1, 2)
666668
if thousandsSeparator and thousandsSeparator == 1 then
667-
integer = integer:sub(2)
669+
integer = utf8.sub(integer, 2)
668670
end
669671
end
670672
else
671-
integer = integer:reverse():gsub("(%d%d%d)", "%1"):reverse()
673+
integer = utf8.reverse(utf8.gsub(utf8.reverse(integer), "(%d%d%d)", "%1"))
672674
end
673-
return colour..minus..integer..fraction:gsub("%.", main.decimalSeparator)
675+
return colour..minus..integer..utf8.gsub(fraction, "%.", main.decimalSeparator)
674676
end)
675677
end
676678

src/TreeData/PSPointsFrame.png

-1.08 KB
Loading
-2.27 KB
Loading

src/UpdateCheck.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ end
7878

7979
ConPrintf("Checking for update...")
8080

81-
local scriptPath = GetScriptPath()
82-
local runtimePath = GetRuntimePath()
81+
local scriptPath = "."
82+
local runtimePath = "."
8383

8484
-- Load and process local manifest
8585
local localVer

0 commit comments

Comments
 (0)