Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fingerprint crashes when o.data is a string #98

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Esam-Bdeir
Copy link

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.

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.
@jlbooker jlbooker changed the title (Second try to merge it) fingerprint crashes when o.data is a string Fingerprint crashes when o.data is a string Nov 15, 2016
@jlbooker jlbooker added this to the v1.1.0 milestone Nov 15, 2016
Copy link
Contributor

@jlbooker jlbooker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

It is a bit interesting that you're using the typeahead with POST requests, since GET requests are more appropriate for fetching typeahead suggestions. However, if this is all that's required to make POST requests work too, then I suppose there's no harm in being flexible on request type.

Can I get another review from @corejavascript/collaborators please?

@Esam-Bdeir
Copy link
Author

I have special business case using post. But I use both in my application (get,post).
/Esam

Skickat från min Samsung Galaxy-smartphone.

-------- Originalmeddelande --------
Från: Jeremy Booker [email protected]
Datum: 2016-11-15 18:53 (GMT+01:00)
Till: "corejavascript/typeahead.js" [email protected]
Kopia: Esam Bdeir [email protected], Author [email protected]
Rubrik: Re: [corejavascript/typeahead.js] Fingerprint crashes when o.data is a string (#98)

@jlbooker approved this pull request.

Looks good to me.

It is a bit interesting that you're using the typeahead with POST requests, since GET requests are more appropriate for fetching typeahead suggestions. However, if this is all that's required to make POST requests work too, then I suppose there's no harm in being flexible on request type.

Can I get another review from @corejavascript/collaboratorshttps://github.com/orgs/corejavascript/teams/collaborators please?

You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHubhttps://github.com//pull/98#pullrequestreview-8658723, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ACK8n-XivdelauZXDKu9Gr-eZWgXDOvWks5q-fGQgaJpZM4KynPP.

@jlbooker jlbooker modified the milestones: v1.1.0, v1.2.0 Dec 21, 2016
//$.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 || {}));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you missing a space here? (o.data &&_.isString(o.data) seems like it should be (o.data && _.isString(o.data).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants