Skip to content

Commit 580330b

Browse files
HushBuggerKockaAdmiralac
authored andcommitted
Escape dangerous HTML characters in GML code
1 parent c94b9cb commit 580330b

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

script.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def parse_text(text: str) -> str:
3535
text,
3636
)
3737
# '&': newline
38-
text = re.sub(r'(?<!`)&\s*', '<br>', text)
38+
text = re.sub(r'(?<!`)&amp;\s*', '<br>', text)
3939
# '%': close message ('%%' to close whole writer)
4040
text = re.sub(
4141
r'(?<!`)%',
@@ -230,6 +230,14 @@ def process_line(
230230
data: Data,
231231
resolve_references: bool = True,
232232
) -> str:
233+
# Escape dangerous HTML characters.
234+
# This preserves strings like "THE LEGEND OF THIS WORLD.#<DELTARUNE.>"
235+
line = re.sub(
236+
r'(&|<)',
237+
lambda matches: {'&': '&amp;', '<': '&lt;'}[matches[1]],
238+
line,
239+
)
240+
233241
# Highlight localized strings
234242
line = re.sub(
235243
r'([A-Za-z0-9_]+loc\((?:\d+, )?)"((?:[^"\\]|\\.)+)(", "[a-z0-9_-]+")\)', # noqa: E501

templates/highlight/text.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<div class="langtext"><span class="highlighted">{{ parsed_text | safe }}</span><div class="langvar">{{ before_var }}{{ variable }}{{ after_var }}</div></div>
1+
<div class="langtext"><span class="highlighted">{{ parsed_text | safe }}</span><div class="langvar">{{ before_var }}{{ variable | safe }}{{ after_var }}</div></div>

0 commit comments

Comments
 (0)