Skip to content

Commit

Permalink
Merge pull request #74 from sakarpanta/master
Browse files Browse the repository at this point in the history
Resolves issues with void tags accepting child elements #73
  • Loading branch information
Hrabal committed Nov 30, 2018
2 parents e286946 + 9a93bdb commit f9822ff
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 6 additions & 0 deletions tempy/elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,12 @@ class VoidTag(Tag):
_void = True
_template = '<{tag}{attrs}/>'

def _insert(self, dom_group, idx=None, prepend=False, name=None):
if dom_group is not None:
raise TagError(self, 'Adding elements to a Void Tag is prohibited.')
else:
super()._insert(self, dom_group, idx, prepend, name)


class Css(Tag):
"""Special class for the style tag.
Expand Down
10 changes: 9 additions & 1 deletion tests/test_Tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"""
import unittest

from tempy.tags import Div, P
from tempy.tags import Div, P, Br
from tempy.elements import Tag, Content, TagAttrs
from tempy.exceptions import TagError, WrongContentError, WrongArgsError

Expand Down Expand Up @@ -82,6 +82,14 @@ def test_parent(self):
p = P().append_to(d)
self.assertEqual(p.parent, d)

def test_void_tag_insertion(self):
with self.assertRaises(TagError):
d = Br()(Div(id='test_void_tag_insertion'))

br = Br()
with self.assertRaises(TagError):
p = Div().append_to(br)

def test_index(self):
father = Div()(Div(), Div())
d = Div().append_to(father)
Expand Down

0 comments on commit f9822ff

Please sign in to comment.