Skip to content

Commit

Permalink
fix: escape arbitrary text in markup
Browse files Browse the repository at this point in the history
  • Loading branch information
P403n1x87 committed Jun 21, 2022
1 parent ccee910 commit 98d3864
Show file tree
Hide file tree
Showing 5 changed files with 311 additions and 364 deletions.
8 changes: 2 additions & 6 deletions austin_tui/adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,10 @@
from austin_tui.view import View
from austin_tui.widgets.graph import FlameGraphData
from austin_tui.widgets.markup import AttrString
from austin_tui.widgets.markup import escape
from austin_tui.widgets.table import TableData


def escape(text: str) -> str:
"""Escape angle brackets."""
return text.replace("<", "&lt;").replace(">", "&gt;")


class Adapter:
"""Model-View adapter.
Expand Down Expand Up @@ -116,7 +112,7 @@ def transform(self) -> AttrString:
"""Retrieve the command line."""
cmd = self._model.austin.command_line
exec, _, args = cmd.partition(" ")
return self._view.markup(f"<exec><b>{exec}</b></exec> {args}")
return self._view.markup(f"<exec><b>{escape(exec)}</b></exec> {escape(args)}")

def update(self, data: AttrString) -> bool:
"""Update the widget."""
Expand Down
5 changes: 4 additions & 1 deletion austin_tui/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
from austin_tui.adapters import ThreadNameAdapter
from austin_tui.model import Model
from austin_tui.view import ViewBuilder
from austin_tui.widgets.markup import escape


class ThreadNav(Enum):
Expand Down Expand Up @@ -258,7 +259,9 @@ def _dump_stats() -> None:
if not line.startswith("# "):
fout.write(line + "\n")
self.view.notification.set_text(
self.view.markup(f"Stats saved as <running>{filename}</running> 📝 ")
self.view.markup(
f"Stats saved as <running>{escape(filename)}</running> 📝 "
)
)
except IOError as e:
self.view.notification.set_text(f"Failed to save stats: {e}")
Expand Down
6 changes: 1 addition & 5 deletions austin_tui/widgets/markup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,14 @@
import curses
from dataclasses import dataclass
from typing import Any, List, TYPE_CHECKING
from xml.sax.saxutils import escape

from lxml import etree

if TYPE_CHECKING:
from austin_tui.view.palette import Palette


def escape(text: str) -> str:
"""Escape angle brackets."""
return text.replace("<", "&lt;").replace(">", "&gt;")


def _unescape(text: str) -> str:
"""Unescape angle brackets."""
return text.replace("&lt;", "<").replace("&gt;", ">")
Expand Down
Loading

0 comments on commit 98d3864

Please sign in to comment.