diff --git a/common/lib/capa/capa/capa_problem.py b/common/lib/capa/capa/capa_problem.py
index 14c590a660..8b32686985 100644
--- a/common/lib/capa/capa/capa_problem.py
+++ b/common/lib/capa/capa/capa_problem.py
@@ -29,6 +29,7 @@ import sys
from lxml import etree
from xml.sax.saxutils import unescape
+from copy import deepcopy
import chem
import chem.chemcalc
@@ -497,11 +498,10 @@ class LoncapaProblem(object):
Used by get_html.
'''
-
if (problemtree.tag == 'script' and problemtree.get('type')
and 'javascript' in problemtree.get('type')):
# leave javascript intact.
- return problemtree
+ return deepcopy(problemtree)
if problemtree.tag in html_problem_semantics:
return
diff --git a/common/lib/capa/capa/tests/test_html_render.py b/common/lib/capa/capa/tests/test_html_render.py
index ca2a3c2e2c..6c74d06ef4 100644
--- a/common/lib/capa/capa/tests/test_html_render.py
+++ b/common/lib/capa/capa/tests/test_html_render.py
@@ -3,6 +3,7 @@ from lxml import etree
import os
import textwrap
import json
+
import mock
from capa.capa_problem import LoncapaProblem
@@ -49,6 +50,8 @@ class CapaHtmlRenderTest(unittest.TestCase):
self.assertEqual(test_element.text, "Test include")
+
+
def test_process_outtext(self):
# Generate some XML with and
xml_str = textwrap.dedent("""
@@ -86,6 +89,25 @@ class CapaHtmlRenderTest(unittest.TestCase):
script_element = rendered_html.find('script')
self.assertEqual(None, script_element)
+ def test_render_javascript(self):
+ # Generate some XML with a
+
+ """)
+
+ # Create the problem
+ problem = LoncapaProblem(xml_str, '1', system=test_system)
+
+ # Render the HTML
+ rendered_html = etree.XML(problem.get_html())
+
+
+ # expect the javascript is still present in the rendered html
+ self.assertTrue("" in etree.tostring(rendered_html))
+
+
def test_render_response_xml(self):
# Generate some XML for a string response
kwargs = {'question_text': "Test question",