diff --git a/lib/searchresult.js b/lib/searchresult.js index 2292d8d..bced079 100644 --- a/lib/searchresult.js +++ b/lib/searchresult.js @@ -86,6 +86,8 @@ SearchResult.prototype.toXML = function toXML(options) { else length = (max > this.documents.length) ? this.documents.length : max; } + else + length = (!ids) ? this.documents.length : ids.length var result = SearchResult.XML_OPEN; @@ -97,10 +99,10 @@ SearchResult.prototype.toXML = function toXML(options) { doc = (ids) ? this.documentHash[ids[i]] : this.documents[i]; if(doc) { - result += ""; - result += "" +doc.snippet+ ""; - result += "" +doc.url+ ""; - result += "" +doc.title+ ""; + result += ""; + result += "" + escape(doc.snippet) + ""; + result += "" + escape(doc.url) + ""; + result += "" + escape(doc.title) + ""; result += ""; } } @@ -155,6 +157,20 @@ SearchResult.XML_QUERY_OPEN = ""; SearchResult.XML_QUERY_CLOSE = ""; SearchResult.XML_CLOSE = ""; +function escape(txt) +{ + + if (typeof txt == 'string') + { + return txt.replace(/&/g, '&') + .replace(//g, '>') + .replace(/"/g, '"'); + } + else + return txt; +} + function serialize(_obj) { switch (typeof _obj) @@ -192,4 +208,4 @@ function serialize(_obj) return 'UNKNOWN'; break; } -}; \ No newline at end of file +}; diff --git a/lib/server.js b/lib/server.js index d94cb35..64c9531 100644 --- a/lib/server.js +++ b/lib/server.js @@ -17,8 +17,10 @@ function validateAlgorithm(algorithm) { * source — By Source Clustering */ + var validAlgorithms = ['lingo', 'stc', 'kmeans']; + algorithm = algorithm.toLowerCase(); - if(algorithm!="lingo" || algorithm!="stc" || algorithm!="kmeans") + if(validAlgorithms.indexOf(algorithm) == -1) algorithm = "lingo"; return algorithm; }; @@ -167,4 +169,4 @@ DocumentClusteringServer.prototype.makeRequest = function makeRequest(search_res req.write(data); req.end(); -}; \ No newline at end of file +};