Skip to content

Commit 56b8650

Browse files
views: tweak xml rendering to better encoding ampersands. use six for string types.
1 parent edb2b7d commit 56b8650

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

Evtx/Views.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
# See the License for the specific language governing permissions and
1717
# limitations under the License.
1818
import sys
19+
import six
1920
import string
2021

2122
from .Nodes import RootNode
@@ -44,8 +45,7 @@ def __init__(self, msg):
4445

4546

4647
def to_xml_string(s):
47-
#s = xml_sax_escape(s, {'"': '"'})
48-
s = s.encode("ascii", "xmlcharrefreplace").decode('ascii')
48+
s = xml_sax_escape(s, {'"': '"'})
4949
return s
5050

5151

@@ -154,11 +154,8 @@ def rec(root_node):
154154
f = _make_template_xml_view(root_node, cache=cache)
155155
subs_strs = []
156156
for sub in root_node.fast_substitutions():
157-
# ugly hack for supporting is-string on py2 and py3
158-
if sys.version_info < (3, ) and isinstance(sub, basestring):
159-
subs_strs.append(sub)
160-
elif sys.version_info >= (3, ) and isinstance(sub, str):
161-
subs_strs.append(sub)
157+
if isinstance(sub, six.string_types):
158+
subs_strs.append(sub.replace('&', '&amp;'))
162159
elif isinstance(sub, RootNode):
163160
subs_strs.append(rec(sub))
164161
elif sub is None:

0 commit comments

Comments
 (0)