Skip to content

Commit

Permalink
Escape safely shell arguments for notify cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-nameless committed Apr 26, 2021
1 parent 3843791 commit 6c126ab
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions tg/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ def get_waveform(file_path: str) -> str:
return base64.b64encode(packed).decode()


safe_map = str.maketrans({"'": "", "`": "", "\"": ""})


def notify(
msg: str,
subtitle: str = "",
Expand All @@ -181,10 +184,10 @@ def notify(
notify_cmd = cmd.format(
icon_path=shlex.quote(config.ICON_PATH),
title=shlex.quote(title),
subtitle=shlex.quote(subtitle),
msg=shlex.quote(msg),
subtitle=shlex.quote(subtitle.translate(safe_map)),
msg=shlex.quote(msg.translate(safe_map)),
)
subprocess.Popen(notify_cmd, shell=False)
subprocess.Popen(notify_cmd, shell=True)


def string_len_dwc(string: str) -> int:
Expand Down

0 comments on commit 6c126ab

Please sign in to comment.