Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Malformed @click links crash Textual application #4248

Closed
xavierog opened this issue Mar 2, 2024 · 4 comments · Fixed by #4313
Closed

Malformed @click links crash Textual application #4248

xavierog opened this issue Mar 2, 2024 · 4 comments · Fixed by #4313
Assignees
Labels
bug Something isn't working Task

Comments

@xavierog
Copy link
Contributor

xavierog commented Mar 2, 2024

Context

I was just trying out the @click syntax.

Expected behaviour

If I create e.g. a Label with incorrect markup, I should get a MarkupError immediately.

Current behaviour

Some @click syntax do not raise a MarkupError and make Textual applications crash when clicked, namely:

  • [@click]
  • [@click=]
  • [@click=()]

MRE:

#!/usr/bin/env python3
from textual.app import App, ComposeResult
from textual.widgets import Label

class ClickMRE(App):
    def compose(self) -> ComposeResult:
        yield Label("[@click]click me and crash[/]") # ValueError in run_action on click
        yield Label("[@click=]click me and crash[/]") # ValueError in run_action on click
        yield Label("[@click=()]click me and crash[/]") # ValueError in run_action on click
        #yield Label("[@click=(,)]click me and crash[/]") # MarkupError in render at startup
        yield Label("[@click=foobar]click me[/]") # ok, nothing happens
        yield Label("[@click=foobar()]click me[/]") # ok, nothing happens
        yield Label("[@click=toggle_dark]click me[/]") # ok, works fine
        yield Label("[@click=toggle_dark()]click me[/]") # ok, works fine

if __name__ == "__main__":
    app = ClickMRE()
    app.run()

Textual Diagnostics

Versions

Name Value
Textual 0.52.1
Rich 13.7.0

Python

Name Value
Version 3.11.8
Implementation CPython
Compiler GCC 13.2.0
Executable ~/whatever/venv/bin/python3

Operating System

Name Value
System Linux
Release 6.6.15-amd64
Version #1 SMP PREEMPT_DYNAMIC Debian 6.6.15-2 (2024-02-04)

Terminal

Name Value
Terminal Application tmux (3.4)
TERM xterm-256color
COLORTERM truecolor
FORCE_COLOR Not set
NO_COLOR Not set

Rich Console options

Name Value
size width=212, height=34
legacy_windows False
min_width 1
max_width 212
is_terminal False
encoding utf-8
max_height 34
justify None
overflow None
no_wrap False
highlight None
markup None
height None
@willmcgugan
Copy link
Collaborator

Those aren't broken markup per se. But obviously it shouldn't crash Textual...

@Textualize Textualize deleted a comment from github-actions bot Mar 14, 2024
@xavierog
Copy link
Contributor Author

FWIW, my current workaround is:

        text = self.render_str(value)
        # Extra check to work around https://github.com/Textualize/textual/issues/4248:
        for span in text.spans:
            if hasattr(span.style, 'meta') and span.style.meta.get('@click') == ():
                raise MarkupError('problematic @click tag')

@davep davep self-assigned this Mar 19, 2024
@davep davep added bug Something isn't working Task labels Mar 19, 2024
davep added a commit to davep/textual that referenced this issue Mar 19, 2024
davep added a commit to davep/textual-sandbox that referenced this issue Mar 19, 2024
Copy link

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

@xavierog
Copy link
Contributor Author

I confirm I can no longer reproduce the issue as of textual 0.54.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Task
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants