Преглед изворни кода

Fix HTML parsing bug when </script> is in the phantomas results json

Gaël Métais пре 10 година
родитељ
комит
2b86a5fdc6
1 измењених фајлова са 6 додато и 1 уклоњено
  1. 6 1
      app/node_controllers/resultsController.js

+ 6 - 1
app/node_controllers/resultsController.js

@@ -34,9 +34,14 @@ var resultsController = function(req, res, googleAnalyticsId) {
             return res.status(404).send('Sorry, test not found...');
             return res.status(404).send('Sorry, test not found...');
         }
         }
 
 
+        // Escape "</script>" because it can interfer with the HTML parser
+        var phantomasResults = results.phantomasResults;
+        phantomasResults = phantomasResults.replace('</script>', '\\u003c/script>');
+
+
         var html = results.htmlTemplate;
         var html = results.htmlTemplate;
         html = html.replace('%%METADATA%%', results.phantomasMetadata);
         html = html.replace('%%METADATA%%', results.phantomasMetadata);
-        html = html.replace('%%RESULTS%%', results.phantomasResults);
+        html = html.replace('%%RESULTS%%', phantomasResults);
         html = html.replace('%%GA_ID%%', googleAnalyticsId);
         html = html.replace('%%GA_ID%%', googleAnalyticsId);
 
 
         res.setHeader('Content-Type', 'text/html');
         res.setHeader('Content-Type', 'text/html');