opensearch.js: make completer less strict about json standards compliance
authorJohn Foerch <jjfoerch@earthlink.net>
Sat, 13 Nov 2010 00:21:31 +0000 (12 19:21 -0500)
committerJohn Foerch <jjfoerch@earthlink.net>
Sat, 13 Nov 2010 00:21:31 +0000 (12 19:21 -0500)
An opensearch is given in http://conkeror.org/issue315 that returns json
suggestion data which is not quite standard.  It includes a single
suggestions array followed by some extra data, where we would otherwise
expect one or two optional arrays for descriptions and urls.  This patch
makes the opensearch webjump completer less strict about such auxiliary
data.  It will just ignore it now, rather than abort.

resolves issue315

modules/opensearch.js

index a99b287..183efaa 100644 (file)
@@ -166,14 +166,16 @@ opensearch_description.prototype = {
                           data.length >= 2 &&
                           typeof(data[0]) == "string" &&
                           data[0] == str &&
-                          data[1] instanceof Array &&
-                          (data[2] == null || (data[2] instanceof Array))))
+                          data[1] instanceof Array))
                         yield co_return(null);
-                    if (data[2] && data[2].length != data[1].length)
-                        data[2] = null;
+                    if (data[2] && data[2] instanceof Array &&
+                        data[2].length == data[1].length)
+                    {
+                        var descriptions = data[2];
+                    }
                     let c = { count: data[1].length,
                               get_string: function (i) String(data[1][i]),
-                              get_description: (data[2] != null ? (function (i) String(data[2][i])) : null),
+                              get_description: (descriptions && (function (i) String(descriptions[i]))),
                               get_input_state: function (i) [String(data[1][i])]
                             };
                     yield co_return(c);