py3status
py3status copied to clipboard
`google_calendar` shows `<` instead of "<" in `{summary}`
Describe the bug
Using google_calendar
with an event title that has a "<" in it, it shows as <
Your py3status version py3status version 3.44 (python 3.10.5) on i3
To Reproduce
- Add module
google_calendar
- Configure
google_calendar
's{format_event}
to include the event title ({summary}
) - Have a google event that includes "<"
- py3status shows
<
instead of the less than sign
Expected behavior py3status should show the less than sign.
Screenshots
This is how the event looks on the google calendar website:
This is how it shows up in py3status:
Additional context
This is my configuration for google_calendar
:
google_calendar {
time_to_max = 99999
events_within_hours = 48
format_event = "[\?if=!is_current [\?color=lime {summary}][ {format_timer}]]"
format_timer = "\?color=time (in [\?if=days {days}d ][\?if=hours {hours}h ][\?if=minutes {minutes}m])"
}
I have tested that https://github.com/ultrabug/py3status/commit/f6da6b8acc141011717a7c24c1f90b12352dce8a does introduce this bug. The commit before that works fine (it also had something to do with HTML formatting)
Does it work fine if you add markup = "pango"
to your google_calendar
config?
Yes, that helps. Thanks! I wasn't aware of the markup
setting.
I'm not sure if markup = "pango"
is just a workaround or if my problem is an actual bug. Feel free to close this issue if it's not a bug.
I'll have to check if somehow the module could detect pango markup config and escape html only when pango is used
Here's an idea... For starters, users could manually specify which placeholders to escape html.
diff --git a/py3status/formatter.py b/py3status/formatter.py
index 9b8659a..e37ea0f 100644
--- a/py3status/formatter.py
+++ b/py3status/formatter.py
@@ -2,6 +2,7 @@ import re
from math import ceil
from numbers import Number
from urllib.parse import parse_qsl
+from html import escape
from py3status.composite import Composite
from py3status.constants import COLOR_NAMES, COLOR_NAMES_EXCLUDED
@@ -322,6 +323,8 @@ class Placeholder:
# no remaining digits following it. If the parameter cannot
# be successfully converted then the format will be removed.
try:
+ if "escape" in self.format:
+ value = escape(value)
if "ceil" in self.format:
value = ceil(float(value))
if "f" in self.format:
diff --git a/py3status/modules/static_string.py b/py3status/modules/static_string.py
index 739f7fb..bb3289f 100644
--- a/py3status/modules/static_string.py
+++ b/py3status/modules/static_string.py
@@ -16,12 +16,16 @@ class Py3status:
"""
# available configuration parameters
- format = "Hello, world!"
+ format = " \| ".join(["{ily}", "{ily2}", "{ily:escape}", "{ily2:escape}"])
def static_string(self):
+ data = {
+ "ily": "I <3 U",
+ "ily2": "I <3 U TOO",
+ }
return {
"cached_until": self.py3.CACHE_FOREVER,
- "full_text": self.py3.safe_format(self.format),
+ "full_text": self.py3.safe_format(self.format, data),
}
$ python static_string.py --term
I <3 U | I <3 U TOO | I <3 U | I <3 U TOO
Just some more info: since 3.47 (and probably #2146), using the markup = pango
workaround makes any event name that has a <
appear completely empty:
Dropping
markup = pango
makes everything work fine again:
I see that the patch has been present since October. I guess there weren't any less than signs in my event names lately. But at least someone might find this information useful if they used the workaround.