Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
b6aa5375
Commit
b6aa5375
authored
Nov 23, 2015
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #25691: Fixed crash on deleting ElementTree.Element attributes.
parent
8bc792a6
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
67 additions
and
0 deletions
+67
-0
Lib/test/test_xml_etree.py
Lib/test/test_xml_etree.py
+27
-0
Lib/test/test_xml_etree_c.py
Lib/test/test_xml_etree_c.py
+32
-0
Misc/NEWS
Misc/NEWS
+2
-0
Modules/_elementtree.c
Modules/_elementtree.c
+6
-0
No files found.
Lib/test/test_xml_etree.py
View file @
b6aa5375
...
...
@@ -244,6 +244,33 @@ class ElementTreeTest(unittest.TestCase):
self
.
assertEqual
(
ET
.
XML
,
ET
.
fromstring
)
self
.
assertEqual
(
ET
.
PI
,
ET
.
ProcessingInstruction
)
def
test_set_attribute
(
self
):
element
=
ET
.
Element
(
'tag'
)
self
.
assertEqual
(
element
.
tag
,
'tag'
)
element
.
tag
=
'Tag'
self
.
assertEqual
(
element
.
tag
,
'Tag'
)
element
.
tag
=
'TAG'
self
.
assertEqual
(
element
.
tag
,
'TAG'
)
self
.
assertIsNone
(
element
.
text
)
element
.
text
=
'Text'
self
.
assertEqual
(
element
.
text
,
'Text'
)
element
.
text
=
'TEXT'
self
.
assertEqual
(
element
.
text
,
'TEXT'
)
self
.
assertIsNone
(
element
.
tail
)
element
.
tail
=
'Tail'
self
.
assertEqual
(
element
.
tail
,
'Tail'
)
element
.
tail
=
'TAIL'
self
.
assertEqual
(
element
.
tail
,
'TAIL'
)
self
.
assertEqual
(
element
.
attrib
,
{})
element
.
attrib
=
{
'a'
:
'b'
,
'c'
:
'd'
}
self
.
assertEqual
(
element
.
attrib
,
{
'a'
:
'b'
,
'c'
:
'd'
})
element
.
attrib
=
{
'A'
:
'B'
,
'C'
:
'D'
}
self
.
assertEqual
(
element
.
attrib
,
{
'A'
:
'B'
,
'C'
:
'D'
})
def
test_simpleops
(
self
):
# Basic method sanity checks.
...
...
Lib/test/test_xml_etree_c.py
View file @
b6aa5375
...
...
@@ -22,6 +22,38 @@ class MiscTests(unittest.TestCase):
finally
:
data
=
None
def
test_del_attribute
(
self
):
element
=
cET
.
Element
(
'tag'
)
element
.
tag
=
'TAG'
with
self
.
assertRaises
(
AttributeError
):
del
element
.
tag
self
.
assertEqual
(
element
.
tag
,
'TAG'
)
with
self
.
assertRaises
(
AttributeError
):
del
element
.
text
self
.
assertIsNone
(
element
.
text
)
element
.
text
=
'TEXT'
with
self
.
assertRaises
(
AttributeError
):
del
element
.
text
self
.
assertEqual
(
element
.
text
,
'TEXT'
)
with
self
.
assertRaises
(
AttributeError
):
del
element
.
tail
self
.
assertIsNone
(
element
.
tail
)
element
.
tail
=
'TAIL'
with
self
.
assertRaises
(
AttributeError
):
del
element
.
tail
self
.
assertEqual
(
element
.
tail
,
'TAIL'
)
with
self
.
assertRaises
(
AttributeError
):
del
element
.
attrib
self
.
assertEqual
(
element
.
attrib
,
{})
element
.
attrib
=
{
'A'
:
'B'
,
'C'
:
'D'
}
with
self
.
assertRaises
(
AttributeError
):
del
element
.
attrib
self
.
assertEqual
(
element
.
attrib
,
{
'A'
:
'B'
,
'C'
:
'D'
})
@
unittest
.
skipUnless
(
cET
,
'requires _elementtree'
)
class
TestAliasWorking
(
unittest
.
TestCase
):
...
...
Misc/NEWS
View file @
b6aa5375
...
...
@@ -106,6 +106,8 @@ Core and Builtins
Library
-------
- Issue #25691: Fixed crash on deleting ElementTree.Element attributes.
- Issue #25624: ZipFile now always writes a ZIP_STORED header for directory
entries. Patch by Dingyuan Wang.
...
...
Modules/_elementtree.c
View file @
b6aa5375
...
...
@@ -1852,6 +1852,12 @@ static int
element_setattro
(
ElementObject
*
self
,
PyObject
*
nameobj
,
PyObject
*
value
)
{
char
*
name
=
""
;
if
(
value
==
NULL
)
{
PyErr_SetString
(
PyExc_AttributeError
,
"can't delete attribute"
);
return
-
1
;
}
if
(
PyUnicode_Check
(
nameobj
))
name
=
_PyUnicode_AsString
(
nameobj
);
if
(
name
==
NULL
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment