Skip to content

Commit

Permalink
Merge pull request #154 from googlefonts/font-filename
Browse files Browse the repository at this point in the history
html: escape font filenames
  • Loading branch information
m4rc1e committed Jul 8, 2024
2 parents 96df26a + 680b945 commit 32b284e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/diffenator2/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import re
from pathlib import Path
from diffenator2.shape import parse_wordlist
from urllib.parse import quote


WIDTH_CLASS_TO_CSS = {
Expand Down Expand Up @@ -196,6 +197,9 @@ def _package(templates, dst, **kwargs):
env = Environment(
loader=FileSystemLoader(os.path.dirname(template_fp)),
)
# jinja2 already has an escaping filter but it only escapes
# a few characters.
env.filters["super_escape"] = quote
template = env.get_template(os.path.basename(template_fp))
doc = template.render(**kwargs)
if "filter_styles" in kwargs:
Expand Down
2 changes: 1 addition & 1 deletion src/diffenator2/templates/CSSFontFace.partial.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@font-face{
src: url("{{ filename }}");
src: url("{{ filename | super_escape }}");
font-family: "{{ cssfamilyname }}";
font-weight: {{ font_weight }};
{% if font_stretch %}font-stretch: {{ font_stretch }};{% endif %}
Expand Down

0 comments on commit 32b284e

Please sign in to comment.