From 7e31806a25ab92e7ea31ee3acd249f24b037e62f Mon Sep 17 00:00:00 2001 From: Esam Bdeir Date: Tue, 15 Nov 2016 15:43:01 +0100 Subject: [PATCH] fingerprint(o) crashes when o.data is a string new Bloodhound({ datumTokenizer: Bloodhound.tokenizers.whitespace, queryTokenizer: Bloodhound.tokenizers.whitespace, aprefetch: '', remote: { url: .....', prepare: function(query, settings) { settings.type = 'POST'; settings.contentType = 'application/json; charset=UTF-8'; // Data will go into POST request body, not querystring settings.data = JSON.stringify({ q: query }); return settings; } } }); In the above scenario, settings.data should go into the request body, not into querystring. The argument name-value pairs should be in JSON format (eg {"objName":"Value"}), not in querystring format (eg objName=Value). Therefore, we set settings.data = JSON.stringify({ q: query }); - a string value. However, this doesn't bode well for function fingerprint(o): $.param(o.data || {}) crashes because it does not expect a single string value. --- src/bloodhound/transport.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/bloodhound/transport.js b/src/bloodhound/transport.js index b5c16dabf9..9504f69b5e 100644 --- a/src/bloodhound/transport.js +++ b/src/bloodhound/transport.js @@ -47,7 +47,10 @@ var Transport = (function() { _fingerprint: function fingerprint(o) { o = o || {}; - return o.url + o.type + $.param(o.data || {}); + //$.param(o.data || {}) crashes because it does not expect a single string value. + //if o.data is string no need to call param + + return o.url + o.type + (o.data &&_.isString(o.data) ? o.data : $.param(o.data || {})); }, _get: function(o, cb) {