Skip to content

Commit 9a31598

Browse files
ass: isolate unicode directional overrides in file names
1 parent c9f06f9 commit 9a31598

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

modules/ass.lua

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ local state = g.state
1111
local style = g.style
1212
local ass = g.ass
1313

14+
--- https://www.unicode.org/reports/tr9/#Explicit_Directional_Isolates
15+
local ISOLATE_DIRECTION_START = '\226\129\168' -- U+2068 FIRST STRONG ISOLATE
16+
local ISOLATE_DIRECTION_END = '\226\129\169' -- U+2069 POP DIRECTIONAL ISOLATE
17+
1418
local function draw()
1519
ass:update()
1620
end
@@ -59,6 +63,15 @@ local function highlight_entry(v)
5963
end
6064
end
6165

66+
---Escapes unwanted unicode control characters that may affect the rest of the display.
67+
---Currently this only isolates unicode directional overrides.
68+
---Based on: https://github.com/mpv-player/mpv/pull/17606
69+
---@param str string
70+
---@return string
71+
local function unicode_escape(str)
72+
return ISOLATE_DIRECTION_START..str..ISOLATE_DIRECTION_END
73+
end
74+
6275
---escape ass values and replace newlines
6376
---@param str string
6477
---@param style_reset string?
@@ -203,7 +216,7 @@ local function update_ass()
203216
end
204217

205218
--adds the actual name of the item
206-
append(v.ass or ass_escape(v.label or v.name, item_style), '\\h')
219+
append(v.ass or ass_escape( unicode_escape(v.label or v.name) , item_style), '\\h')
207220
if g.ALIGN_X == 'right' then draw_cursor(i, o.cursor_icon_flipped) end
208221
newline()
209222
end

0 commit comments

Comments
 (0)