2009/dap/ReSpec.js/js respec.js,1.77,1.78

Update of /sources/public/2009/dap/ReSpec.js/js
In directory hutz:/tmp/cvs-serv17936/ReSpec.js/js

Modified Files:
	respec.js 
Log Message:
detect and avoid bad IDs generated from WebIDL

Index: respec.js
===================================================================
RCS file: /sources/public/2009/dap/ReSpec.js/js/respec.js,v
retrieving revision 1.77
retrieving revision 1.78
diff -u -d -r1.77 -r1.78
--- respec.js	21 Jan 2010 17:44:55 -0000	1.77
+++ respec.js	28 Jan 2010 15:29:20 -0000	1.78
@@ -940,6 +940,7 @@
         var match = /^\s*interface\s+([A-Za-z][A-Za-z0-9]*)(?:\s+:\s*([^{]+)\s*)?/.exec(str);
         if (match) {
             inf.id = match[1];
+            inf.refId = this._id(inf.id);
             if (match[2]) inf.superclasses = match[2].split(/\s*,\s*/);
         }
         else {
@@ -951,7 +952,10 @@
     exception:  function (exc, str, idl) {
         exc.type = "exception";
         var match = /^\s*exception\s+([A-Za-z][A-Za-z0-9]*)\s*/.exec(str);
-        if (match) exc.id = match[1];
+        if (match) {
+            exc.id = match[1];
+            exc.refId = this._id(exc.id);
+        }
         else error("Expected exception, got: " + str);
         return exc;
     },
@@ -974,6 +978,7 @@
             }
             tdf.datatype = type;
             tdf.id = match[2];
+            tdf.refId = this._id(tdf.id);
             tdf.description = sn.documentFragment();
             sn.copyChildren(idl, tdf.description);
         }
@@ -989,6 +994,7 @@
         var match = /^\s*(.+?)\s+implements\s+(.+)\s*$/.exec(str);
         if (match) {
             imp.id = match[1];
+            imp.refId = this._id(imp.id);
             imp.datatype = match[2];
             imp.description = sn.documentFragment();
             sn.copyChildren(idl, imp.description);
@@ -1020,6 +1026,7 @@
         var hadId = false;
         if (dd.id) hadId = true;
         else dd.id = "temporaryIDJustForCSS";
+        dd.refId = this._id(dd.id);
         // var sgrs = sn.findNodes("*[@class='setraises' or @class='getraises' or]", dd);
         var sgrs = document.querySelectorAll("#" + dd.id + " .getraises, #" + dd.id + " .setraises");
         if (!hadId) dd.removeAttribute("id");
@@ -1046,6 +1053,7 @@
             }
             mem.datatype = type;
             mem.id = match[3];
+            mem.refId = this._id(mem.id);
             mem.raises = [];
             if (sgrs.length) {
                 for (var i = 0; i < sgrs.length; i++) {
@@ -1095,6 +1103,7 @@
             }
             mem.datatype = type;
             mem.id = match[2];
+            mem.refId = this._id(mem.id);
             mem.value = match[3];
             return mem;
         }
@@ -1116,6 +1125,7 @@
             }
             mem.datatype = type;
             mem.id = match[2];
+            mem.refId = this._id(mem.id);
             mem.params = [];
             var prm = match[3];
             mem.raises = [];
@@ -1173,6 +1183,7 @@
                         }
                         p.datatype = type;
                         p.id = match[2];
+                        p.refId = this._id(p.id);
                         p.description = sn.documentFragment();
                         sn.copyChildren(dd, p.description);
                         mem.params.push(p);
@@ -1205,6 +1216,7 @@
                         }
                         p.datatype = type;
                         p.id = match[2];
+                        p.refId = this._id(p.id);
                         mem.params.push(p);
                     }
                     else {
@@ -1295,7 +1307,7 @@
         }
         else if (obj.type == "interface" || obj.type == "exception") {
             var df = sn.documentFragment();
-            var curLnk = "widl-" + obj.id + "-";
+            var curLnk = "widl-" + obj.refId + "-";
             var types = ["attribute", "method", "constant"];
             for (var i = 0; i < types.length; i++) {
                 var type = types[i];
@@ -1316,7 +1328,7 @@
                 var dl = sn.element("dl", { "class": type + "s" }, sec);
                 for (var j = 0; j < things.length; j++) {
                     var it = things[j];
-                    var dt = sn.element("dt", { id: curLnk + it.id }, dl);
+                    var dt = sn.element("dt", { id: curLnk + it.refId }, dl);
                     sn.element("code", {}, dt, it.id);
                     var desc = sn.element("dd", {}, dl, [it.description]);
                     if (type == "method") {
@@ -1469,7 +1481,7 @@
         else if (obj.type == "typedef") {
             var nullable = obj.nullable ? "?" : "";
             var arr = obj.array ? "[]" : "";
-            return  "<span class='idlTypedef' id='idl-def-" + obj.id + "'>typedef <span class='idlTypedefType'>" + 
+            return  "<span class='idlTypedef' id='idl-def-" + obj.refId + "'>typedef <span class='idlTypedefType'>" + 
                     this.writeDatatype(obj.datatype) +
                     "</span>" + arr + nullable + " <span class='idlTypedefID'>" + obj.id + "</span>;</span>";
         }
@@ -1477,7 +1489,7 @@
             return  "<span class='idlImplements'><a>" + obj.id + "</a> implements <a>" + obj.datatype + "</a>;";
         }
         else if (obj.type == "interface") {
-            var str = "<span class='idlInterface' id='idl-def-" + obj.id + "'>";
+            var str = "<span class='idlInterface' id='idl-def-" + obj.refId + "'>";
             if (obj.extendedAttributes) str += this._idn(indent) + "[<span class='extAttr'>" + obj.extendedAttributes + "</span>]\n";
             str += this._idn(indent) + "interface <span class='idlInterfaceID'>" + obj.id + "</span>";
             if (obj.superclasses && obj.superclasses.length) str += " : " +
@@ -1497,7 +1509,7 @@
                 else if (it.type == "constant") maxConst = (len > maxConst) ? len : maxConst;
                 if (it.type == "attribute" && it.readonly) hasRO = true;
             });
-            var curLnk = "widl-" + obj.id + "-";
+            var curLnk = "widl-" + obj.refId + "-";
             for (var i = 0; i < obj.children.length; i++) {
                 var ch = obj.children[i];
                 if (ch.type == "attribute") str += this.writeAttribute(ch, maxAttr, indent + 1, curLnk, hasRO);
@@ -1508,7 +1520,7 @@
             return str;
         }
         else if (obj.type == "exception") {
-            var str = "<span class='idlException' id='idl-def-" + obj.id + "'>";
+            var str = "<span class='idlException' id='idl-def-" + obj.refId + "'>";
             if (obj.extendedAttributes) str += this._idn(indent) + "[<span class='extAttr'>" + obj.extendedAttributes + "</span>]\n";
             str += this._idn(indent) + "exception <span class='idlExceptionID'>" + obj.id + "</span> {\n";
             var maxAttr = 0, maxConst = 0, hasRO = false;
@@ -1520,7 +1532,7 @@
                 else if (it.type == "constant") maxConst = (len > maxConst) ? len : maxConst;
                 if (it.type == "attribute" && it.readonly) hasRO = true;
             });
-            var curLnk = "widl-" + obj.id + "-";
+            var curLnk = "widl-" + obj.refId + "-";
             for (var i = 0; i < obj.children.length; i++) {
                 var ch = obj.children[i];
                 if (ch.type == "attribute") str += this.writeAttribute(ch, maxAttr, indent + 1, curLnk, hasRO);
@@ -1556,7 +1568,7 @@
         var arr = attr.array ? "[]" : "";
         str += "<span class='idlAttrType'>" + this.writeDatatype(attr.datatype) + arr + nullable + "</span> ";
         for (var i = 0; i < pad; i++) str += " ";
-        str += "<span class='idlAttrName'><a href='#" + curLnk + attr.id + "'>" + attr.id + "</a></span>";
+        str += "<span class='idlAttrName'><a href='#" + curLnk + attr.refId + "'>" + attr.id + "</a></span>";
         if (gets.length) {
             str += " getraises (" +
                    gets.map(function (it) { return "<span class='idlRaises'><a>" + it.id + "</a></span>"; }).join(", ") +
@@ -1582,7 +1594,7 @@
         var arr = meth.array ? "[]" : "";
         str += "<span class='idlMethType'>" + this.writeDatatype(meth.datatype) + arr + nullable + "</span> ";
         for (var i = 0; i < pad; i++) str += " ";
-        str += "<span class='idlMethName'><a href='#" + curLnk + meth.id + "'>" + meth.id + "</a></span> (";
+        str += "<span class='idlMethName'><a href='#" + curLnk + meth.refId + "'>" + meth.id + "</a></span> (";
         var obj = this;
         str += meth.params.map(function (it) {
                                     var nullable = it.nullable ? "?" : "";
@@ -1617,7 +1629,7 @@
         var nullable = cons.nullable ? "?" : "";
         str += "<span class='idlConstType'><a>" + cons.datatype + "</a>" + nullable + "</span> ";
         for (var i = 0; i < pad; i++) str += " ";
-        str += "<span class='idlConstName'><a href='#" + curLnk + cons.id + "'>" + cons.id + "</a></span> = " +
+        str += "<span class='idlConstName'><a href='#" + curLnk + cons.refId + "'>" + cons.id + "</a></span> = " +
                "<span class='idlConstValue'>" + cons.value + "</span>;</span>\n";
         return str;
     },
@@ -1644,6 +1656,9 @@
         return str.split(/\s+/).join(" ");
     },
     
+    _id:    function (id) {
+        return id.replace(/[^a-zA-Z_-]/g, "");
+    },
 };
 
 // hackish, but who cares?

Received on Thursday, 28 January 2010 15:29:24 UTC