Skip to content

Commit b119895

Browse files
committed
Fix InvalidCharacterError: HTML-escape generated password before display
1 parent 5d8e8d7 commit b119895

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

app.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import os
1818
import time
19+
from html import escape
1920

2021
# --- Provide safe defaults BEFORE importing the core module ----------------
2122
# The core module reads these via os.getenv() at call time. Setting them here
@@ -172,7 +173,9 @@
172173
if res:
173174
st.markdown("### Result")
174175
display = res["password"] if show_pw else "•" * len(res["password"])
175-
st.markdown(f'<div class="tl-pw">{display}</div>', unsafe_allow_html=True)
176+
# Escape before injecting: generated passwords contain HTML-special chars
177+
# like < > & " which would otherwise break the markup (InvalidCharacterError).
178+
st.markdown(f'<div class="tl-pw">{escape(display)}</div>', unsafe_allow_html=True)
176179
st.markdown('<div class="tl-note">Triple-click to select · nothing is stored server-side</div>',
177180
unsafe_allow_html=True)
178181

0 commit comments

Comments
 (0)