shithub: puzzles

Download patch

ref: 3e39f6b80b2b6e4308e2d3a9fa436cbbb9d9b621
parent: 1264bccf4053d06d106d37b60516f7d27bfc8420
author: Simon Tatham <anakin@pobox.com>
date: Sun Mar 31 05:58:45 EDT 2013

Stop using the dangerously unescaped 'innerHTML' for <option>
contents; use document.createTextNode like I do everywhere else.

[originally from svn r9787]

--- a/emcclib.js
+++ b/emcclib.js
@@ -64,8 +64,8 @@
      */
     js_add_preset: function(ptr) {
         var option = document.createElement("option");
-        option.value = Pointer_stringify(ptr);
-        option.innerHTML = Pointer_stringify(ptr);
+        option.value = gametypeoptions.length;
+        option.appendChild(document.createTextNode(Pointer_stringify(ptr)));
         gametypeselector.appendChild(option);
         gametypeoptions.push(option);
     },
@@ -77,14 +77,12 @@
      * dropdown.
      */
     js_get_selected_preset: function() {
-        var val = 0;
         for (var i in gametypeoptions) {
             if (gametypeoptions[i].selected) {
-                val = i;
-                break;
+                return gametypeoptions[i].value;
             }
         }
-        return val;
+        return 0;
     },
 
     /*
@@ -592,8 +590,8 @@
         var options = [];
         for (var i in items) {
             var option = document.createElement("option");
-            option.value = items[i];
-            option.innerHTML = items[i];
+            option.value = i;
+            option.appendChild(document.createTextNode(items[i]));
             if (i == initvalue) option.selected = true;
             dropdown.appendChild(option);
             options.push(option);
@@ -605,7 +603,7 @@
             var val = 0;
             for (var i in options) {
                 if (options[i].selected) {
-                    val = i;
+                    val = options[i].value;
                     break;
                 }
             }