Skip to content

Commit

Permalink
[W3C] DOM Core Text object - splitText method
Browse files Browse the repository at this point in the history
  • Loading branch information
buffer committed Jun 7, 2021
1 parent 7068873 commit 737c37c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
9 changes: 9 additions & 0 deletions tests/functional/test_misc_ie90.py
Original file line number Diff line number Diff line change
Expand Up @@ -1402,3 +1402,12 @@ def test_testIEVisibility(self, caplog):
"[Window] Alert Text: document.msVisibilityState: visible"]

self.do_perform_test(caplog, sample, expected)

def test_testSplitText(self, caplog):
sample = os.path.join(self.misc_path, "testSplitText.html")
expected = ["p.childNodes.length before splitText: 1",
"foobar value after splitText: foo",
"bar value: bar",
"p.childNodes.length after splitText: 2"]

self.do_perform_test(caplog, sample, expected)
8 changes: 7 additions & 1 deletion thug/DOM/W3C/Core/Text.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ def __init__(self, doc, tag):
CharacterData.__init__(self, doc, tag)

def splitText(self, offset):
raise DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR)
newNode = self.doc.createTextNode(self.data[offset:])
self.data = self.data[:offset]

if self.parentNode:
self.parentNode.insertBefore(newNode, self.nextSibling)

return newNode

def getNodeValue(self):
return str(self.data)
Expand Down

0 comments on commit 737c37c

Please sign in to comment.