Skip to content

select.lua: put track name in directional isolate#17606

Open
afishhh wants to merge 1 commit intompv-player:masterfrom
afishhh:select-title-isolate
Open

select.lua: put track name in directional isolate#17606
afishhh wants to merge 1 commit intompv-player:masterfrom
afishhh:select-title-isolate

Conversation

@afishhh
Copy link
Copy Markdown
Contributor

@afishhh afishhh commented Mar 19, 2026

Prevents RTL track names from messing up the subtitle select menu where the name is preceded only by neutral characters.

Fixes: #17605

@afishhh afishhh force-pushed the select-title-isolate branch from c2b1a47 to 62e97c8 Compare March 19, 2026 12:12

local function format_track(track)
local bitrate = track["demux-bitrate"] or track["hls-bitrate"]
local bidi_fsi = "\226\129\168" -- U+2068 FIRST STRONG ISOLATE
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd put these someplace more global. There could be other places at the OSC which would want to use it.

Also, the casual code reader probably doesn't know what "FIRST STRONG ISOLATE" means, so a comment could help (but "POP DIRECTIONAL ISOLATE" does sound self-describing)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd put these someplace more global. There could be other places at the OSC which would want to use it.

then it can be moved to common place based on required uses.

Also, the casual code reader probably doesn't know what "FIRST STRONG ISOLATE" means

The causal code reader can use google or chatgpt to educate themselves.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the casual code reader probably doesn't know what "FIRST STRONG ISOLATE" means

Can add a comment pointing to the fine manual spec at https://www.unicode.org/reports/tr9/#Explicit_Directional_Isolates

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not the OSC dude

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then it can be moved to common place based on required uses.

Technically, to avoid such random issues in the future, all arbitrary metadata strings should use it. Not just this specific display.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically, to avoid such random issues in the future, all arbitrary metadata strings should use it. Not just this specific display.

Yes, and once this change is created the correct design can be applied to handling this escaping.

kasper93

This comment was marked as spam.

Prevents RTL track names from messing up the subtitle select menu where
the name is preceded only by neutral characters.

Fixes: mpv-player#17605
@afishhh afishhh force-pushed the select-title-isolate branch from 62e97c8 to df383d5 Compare March 19, 2026 12:22
@avih
Copy link
Copy Markdown
Member

avih commented Mar 19, 2026

Would that work also for bullet and RTL text and without any English text at all?

@avih
Copy link
Copy Markdown
Member

avih commented Mar 19, 2026

I would really prefer if there was a comment along the lines of:

-- The default text direction is LTR, but it can be RTL depending on content.
-- To isolate arbitrary text so that it doesn't affect the global direction,
-- like in <bullet> <text>, put the text between U+2068 and U+2069.

@verygoodlee
Copy link
Copy Markdown
Contributor

verygoodlee commented Mar 19, 2026

The scope of this fix is too limited. there are still issues with the context-menu that are known at present #17605 (comment),
and third-party scripts also use mp.input.select to show their own menus, we need to ensure that third-party scripts can safely call the menu API without having to handle this issue themselves.

@avih
Copy link
Copy Markdown
Member

avih commented Mar 19, 2026

The scope of this fix is too limited.

Indeed. This should probably be applied wherever arbitrary strings are used in the UI.

This includes the lua menu, maybe all arbitrary metadata strings at osc.lua, and possibly elsewhere too (console.lua?)

@afishhh
Copy link
Copy Markdown
Contributor Author

afishhh commented Mar 19, 2026

The scope of this fix is too limited. there are still issues with the context-menu that are known at present #17605 (comment)

This also fixes the issue in the context menu because it uses the same function.

and third-party scripts also

Maybe a utility function that wraps some text inside a directional isolate (maybe even handles any rogue PDIs if we care) could make sense but I wouldn't know where to put that and not sure if it makes sense in this PR.

@verygoodlee
Copy link
Copy Markdown
Contributor

verygoodlee commented Mar 19, 2026

The scope of this fix is too limited. there are still issues with the context-menu that are known at present #17605 (comment)

This also fixes the issue in the context menu because it uses the same function.

No, not only the track titles may contain RTL characters, but also the file names. And even the user's menu.conf may be written in RTL language.

@guidocella
Copy link
Copy Markdown
Contributor

guidocella commented Mar 19, 2026

Sounds like it should be fixed in libass.

@avih
Copy link
Copy Markdown
Member

avih commented Mar 19, 2026

Sounds like it should be fixed in libass.

It's not a problem in libass. That's how Unicode works.

It should be fixed in whoever uses libass to display arbitrary strings but wants them to end up primarily LTR.

@verygoodlee
Copy link
Copy Markdown
Contributor

This fix even breaks the track list of Windows native context-menu, the two added characters would appear as garbled text.
33333

@afishhh
Copy link
Copy Markdown
Contributor Author

afishhh commented Mar 21, 2026

This fix even breaks the track list of Windows native context-menu,

I don't know what to do about this and don't use Windows, someone familiar with the Windows context menu should figure out what to do here. I kind of don't want to believe it doesn't support reordering since that'd be very dumb, but it's Windows.

Discussion in #17605 suggests we could also achieve stronger isolation by using an ASS trick but that'd obviously not work in the native menu either. So whether we can use that trick also depends on what we do with the Windows context menu.

@kasper93
Copy link
Copy Markdown
Member

I don't know what to do about this and don't use Windows, someone familiar with the Windows context menu should figure out what to do here.

What's to figure out? It clearly doesn't handle those codes and display them as-is. I believe LTR/RTL marks works, isolates does not as we can see.

@afishhh
Copy link
Copy Markdown
Contributor Author

afishhh commented Mar 21, 2026

What's to figure out? It clearly doesn't handle those codes and display them as-is. I believe LTR/RTL marks works, isolates does not as we can see.

Right so I should special case Windows to just not do anything then? Since apparently it's already "correct" there (see #17605 (comment), maybe it acts as if paragraph direction was always LTR).

@kasper93
Copy link
Copy Markdown
Member

Not sure what is the best approach here. Sounds like we should filter it in menu.c, and let it fall-through to other places. Also does it work in terminals? I tested mine and seems ok, but not sure about others.

@guidocella
Copy link
Copy Markdown
Contributor

Right so I should special case Windows to just not do anything then? Since apparently it's already "correct" there (see #17605 (comment), maybe it acts as if paragraph direction was always LTR).

Windows users can also use the Lua menu by setting --load-context-menu=yes. Also you can't know which will be used when writing menu-data.

@afishhh
Copy link
Copy Markdown
Contributor Author

afishhh commented Mar 21, 2026

Not related to the native menu problem but another way to make this more foolproof that doesn't involve ASS tricks is just:

  • Removing all unpaired PDIs in the string
  • Closing all unclosed {LR,RL,FS}Is with additional PDIs at the end

https://unicode.org/reports/tr9/#X6a seems carefully designed to allow this to work without footguns (i.e. we don't need to worry about embedding level limits or other unclosed control codes). Even if it doesn't work in all cases we already accept \xC2\x92a0{\\fs120}{\\alpha&HF0&} as a title so malicious input has better options :)

@kasper93
Copy link
Copy Markdown
Member

kasper93 commented Mar 22, 2026

This fix even breaks the track list of Windows native context-menu, the two added characters would appear as garbled text.
33333

Please upvote the issue here: https://aka.ms/AA10adi9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

right-to-left language like Arabic makes the track menu a mess

5 participants