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

Invalid encoded characters on dynamic requests for `{{query}}` inside $.Ajax.url #184

Closed
nicodewet opened this Issue Apr 20, 2016 · 8 comments

Comments

Projects
None yet
3 participants
@nicodewet

nicodewet commented Apr 20, 2016

When performing an HTTP GET with a dynamic configuration, a forward slash in the request appears to be sanitised away whereas in my case I'm expecting and need URI encoding.

It may well be that onSendRequest (node, query) callback is what one should use (for hand-crancked uriEncoding), but having stepped through the execution, the sanitisation happens after onSendRequest gets called.

So, my question is basically, if I do a HTTP GET request, and need for a forward slash in {{query}} to be URI encoded (%2F) in the outgoing request, how do I make this happen?

Just to add some context to the cited use case, in my case the need for the preservation and URI encoding of a forward slash in {{query}} stems from the need to search addresses backed by a RESTful endpoint. When it comes to addresses a forward slash will be common e.g. when specifying say an apartment number then street number e.g. 23/100 Foo rd.

I'm on 2.5.0 of jquery-typeahead.

@running-coder

This comment has been minimized.

Owner

running-coder commented Apr 21, 2016

Hey nico, thanks for raising the issue. Indeed i was sanitizing the string instead of applying encodeURIComponent. If you want to modify further the request before it gets sent you can wrap your ajax request in a function, ex:

source: {
    myGroupName: {
        // ajax key is replacing url key for version 2.6.0+
        ajax: function (query) {
            // Modify the query here
            return {
                url: "/myData.json?q=" + query,
                // optional path to your array of results inside the response
                path: data,
                // OR
                data: {
                    q: query
                }
            }
        }
    }
}

@running-coder running-coder added the Bug label Apr 21, 2016

@running-coder running-coder added this to the 2.6.0 milestone Apr 21, 2016

@running-coder running-coder changed the title from Forward slash in {{query}} to Invalid encoded characters on dynamic requests for `{{query}}` Apr 21, 2016

running-coder added a commit that referenced this issue Apr 21, 2016

@running-coder

This comment has been minimized.

Owner

running-coder commented Apr 21, 2016

Should be good now on the develop branch. The next version 2.6.0 should be available today / tomorrow. Let me know if anything.

Thanks

running-coder added a commit that referenced this issue Apr 22, 2016

Version 2.6.0
*Breaking change*
- Update Typeahead source option: source.group.url.url has been replaced by source.group.ajax.url

Features
- #69, #179 Added groupTemplate option
- #183 Allow Typeahead to search for deep source object keys

Fixes
- #149 Support for Mobiles
- #181 IE8 incompatibility
- #182 Fixed double form submit when the "Enter" key is pressed & fixed JS error when searching for an undefined or numeric value
- #184 Invalid encoded characters on dynamic requests for `{{query}}`

Notes
- Reworked the source.group options, url has been replaced by ajax
- Removed the source.group.ignore option, use source.group.filter instead
@bpadamata

This comment has been minimized.

bpadamata commented Jul 18, 2016

Hi, I am working with the latest version (2.6.1) and I could not see the fixed changes of applying encodeURIComponent in it. So I am still having this issue.

The earlier version (2.6.0) includes the changes as below
xhrObject.request.url = xhrObject.request.url.replace('{{query}}', encodeURIComponent(scope.query));

However it is missing in the current release and this is how source looks like
xhrObject.request.url = xhrObject.request.url.replace('{{query}}', scope.query);

@bpadamata

This comment has been minimized.

bpadamata commented Jul 18, 2016

It appears that you have modified this solution during fixing '#189 - Twice url encoding'

@running-coder

This comment has been minimized.

Owner

running-coder commented Jul 19, 2016

Hey @bpadamata, I think I removed it because jQuery was already encoding the characters which was causing a double encoding, see #189

@bpadamata

This comment has been minimized.

bpadamata commented Jul 19, 2016

With the latest release I am unable to use a forward slash in {{query}} for the outgoing request. So I am restricted to used only the fixed version (2.6.0).

@running-coder

This comment has been minimized.

Owner

running-coder commented Jul 19, 2016

Just tested... here is my result:

// no encodeURIComponent
url: '/test.json?q={{query}}',

// jQuery handles encodeURIComponent
url: '/test.json',
data: {
    q: '{{query}}'
},

Are you using the first example? can you switch to the second example?

@running-coder running-coder reopened this Jul 19, 2016

@running-coder running-coder modified the milestones: 2.7.0, 2.6.0 Jul 19, 2016

@running-coder running-coder changed the title from Invalid encoded characters on dynamic requests for `{{query}}` to Invalid encoded characters on dynamic requests for `{{query}}` inside $.Ajax.url Jul 19, 2016

running-coder pushed a commit that referenced this issue Jul 19, 2016

@running-coder

This comment has been minimized.

Owner

running-coder commented Jul 19, 2016

This commit should fix the Ajax.url case, Let me know if any issue.

Thanks!

running-coder added a commit that referenced this issue Aug 13, 2016

Version 2.7.0
Features
    #198 Using an async function as a data source
    #195 Add `onCancel` callback

Fixes
    #221 On form reset, input field clears but the value persists
    #211 Global reset styling on inputs has bad effects, keep them local to instantiation
    #208 No distinction between "click" and "enter" selection in onClick callbacks
    #193 Clicking on a suggested option does not select it on IE10/11 Bug
    #184 Invalid encoded characters on dynamic requests for `{{query}}` inside $.Ajax.url

More goodies
    #222 Add JSHint validation
    #215 Fix "main" property in bower.json
    #213 Allow scss customization via !default

running-coder added a commit that referenced this issue Aug 13, 2016

Version 2.7.0
Features
    #198 Using an async function as a data source
    #195 Add `onCancel` callback

Fixes
    #221 On form reset, input field clears but the value persists
    #211 Global reset styling on inputs has bad effects, keep them local to instantiation
    #208 No distinction between "click" and "enter" selection in onClick callbacks
    #193 Clicking on a suggested option does not select it on IE10/11 Bug
    #184 Invalid encoded characters on dynamic requests for `{{query}}` inside $.Ajax.url

More goodies
    #222 Add JSHint validation
    #215 Fix "main" property in bower.json
    #213 Allow scss customization via !default

running-coder added a commit that referenced this issue Aug 13, 2016

Version 2.7.0
Features
    #198 Using an async function as a data source
    #195 Add `onCancel` callback

Fixes
    #221 On form reset, input field clears but the value persists
    #211 Global reset styling on inputs has bad effects, keep them local to instantiation
    #208 No distinction between "click" and "enter" selection in onClick callbacks
    #193 Clicking on a suggested option does not select it on IE10/11 Bug
    #184 Invalid encoded characters on dynamic requests for `{{query}}` inside $.Ajax.url

More goodies
    #222 Add JSHint validation
    #215 Fix "main" property in bower.json
    #213 Allow scss customization via !default

running-coder added a commit that referenced this issue Aug 13, 2016

Version 2.7.0
Features
    #198 Using an async function as a data source
    #195 Add `onCancel` callback

Fixes
    #221 On form reset, input field clears but the value persists
    #211 Global reset styling on inputs has bad effects, keep them local to instantiation
    #208 No distinction between "click" and "enter" selection in onClick callbacks
    #193 Clicking on a suggested option does not select it on IE10/11 Bug
    #184 Invalid encoded characters on dynamic requests for `{{query}}` inside $.Ajax.url

More goodies
    #222 Add JSHint validation
    #215 Fix "main" property in bower.json
    #213 Allow scss customization via !default

running-coder added a commit that referenced this issue Aug 13, 2016

Version 2.7.0
Features
    #198 Using an async function as a data source
    #195 Add `onCancel` callback

Fixes
    #221 On form reset, input field clears but the value persists
    #211 Global reset styling on inputs has bad effects, keep them local to instantiation
    #208 No distinction between "click" and "enter" selection in onClick callbacks
    #193 Clicking on a suggested option does not select it on IE10/11 Bug
    #184 Invalid encoded characters on dynamic requests for `{{query}}` inside $.Ajax.url

More goodies
    #222 Add JSHint validation
    #215 Fix "main" property in bower.json
    #213 Allow scss customization via !default

running-coder added a commit that referenced this issue Aug 13, 2016

Version 2.7.0
Features
    #198 Using an async function as a data source
    #195 Add `onCancel` callback

Fixes
    #221 On form reset, input field clears but the value persists
    #211 Global reset styling on inputs has bad effects, keep them local to instantiation
    #208 No distinction between "click" and "enter" selection in onClick callbacks
    #193 Clicking on a suggested option does not select it on IE10/11 Bug
    #184 Invalid encoded characters on dynamic requests for `{{query}}` inside $.Ajax.url

More goodies
    #222 Add JSHint validation
    #215 Fix "main" property in bower.json
    #213 Allow scss customization via !default

running-coder added a commit that referenced this issue Aug 13, 2016

Version 2.7.0
Features
    #198 Using an async function as a data source
    #195 Add `onCancel` callback

Fixes
    #221 On form reset, input field clears but the value persists
    #211 Global reset styling on inputs has bad effects, keep them local to instantiation
    #208 No distinction between "click" and "enter" selection in onClick callbacks
    #193 Clicking on a suggested option does not select it on IE10/11 Bug
    #184 Invalid encoded characters on dynamic requests for `{{query}}` inside $.Ajax.url

More goodies
    #222 Add JSHint validation
    #215 Fix "main" property in bower.json
    #213 Allow scss customization via !default

running-coder added a commit that referenced this issue Aug 13, 2016

Version 2.7.0
Features
    #198 Using an async function as a data source
    #195 Add `onCancel` callback

Fixes
    #221 On form reset, input field clears but the value persists
    #211 Global reset styling on inputs has bad effects, keep them local to instantiation
    #208 No distinction between "click" and "enter" selection in onClick callbacks
    #193 Clicking on a suggested option does not select it on IE10/11 Bug
    #184 Invalid encoded characters on dynamic requests for `{{query}}` inside $.Ajax.url

More goodies
    #222 Add JSHint validation
    #215 Fix "main" property in bower.json
    #213 Allow scss customization via !default
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment