Skip to content

Commit ab03d2c

Browse files
committed
Enable autoescape by default
1 parent 5602296 commit ab03d2c

3 files changed

Lines changed: 7 additions & 9 deletions

File tree

hyperscript/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from hyperscript.element import Element, SafeStr
44

5-
AUTOESCAPE = False
5+
AUTOESCAPE = True
66

77

88
def h(tag: str, *args: Any, autoescape: Optional[bool] = None) -> Element:

hyperscript/element.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class SafeStr(str):
2929
class Element:
3030
__hash__ = object.__hash__
3131

32-
def __init__(self, tag: str, *args: Any, autoescape: bool = False) -> None:
32+
def __init__(self, tag: str, *args: Any, autoescape: bool = True) -> None:
3333
self.tag, self.classes, self.id_selector = self.parse_tag(tag)
3434
self.autoescape = autoescape
3535
self.attrs, self.children = self.parse_args(args)

tests/test_element.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,22 +81,20 @@ def test_equality(self) -> None:
8181
self.assertNotEqual(h("div", h("p", "Foo")), h("div", h("p", "Bar")))
8282

8383
def test_escape(self) -> None:
84-
self.assertEqual(str(h("div", "<&>")), "<div><&></div>")
84+
self.assertEqual(str(h("div", "<&>", autoescape=False)), "<div><&></div>")
8585

86-
self.assertEqual(
87-
str(h("div", "<&>", autoescape=True)), "<div>&lt;&amp;&gt;</div>"
88-
)
86+
self.assertEqual(str(h("div", "<&>")), "<div>&lt;&amp;&gt;</div>")
8987

9088
self.assertEqual(
91-
str(h("div", {"prop": "<&>"}, autoescape=True)),
89+
str(h("div", {"prop": "<&>"})),
9290
'<div prop="&lt;&amp;&gt;"></div>',
9391
)
9492

9593
def test_safe(self) -> None:
96-
self.assertEqual(str(h("div", safe("<&>"), autoescape=True)), "<div><&></div>")
94+
self.assertEqual(str(h("div", safe("<&>"))), "<div><&></div>")
9795

9896
self.assertEqual(
99-
str(h("div", {"prop": safe("<&>")}, autoescape=True)),
97+
str(h("div", {"prop": safe("<&>")})),
10098
'<div prop="<&>"></div>',
10199
)
102100

0 commit comments

Comments
 (0)