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

getQuery with hash before #227

Merged
merged 3 commits into from Mar 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/queryString/getQuery.js
Expand Up @@ -4,7 +4,7 @@ define(function () {
* Gets full query as string with all special chars decoded.
*/
function getQuery(url) {
url = url.replace(/#.*/, ''); //removes hash (to avoid getting hash query)
// url = url.replace(/#.*\?/, '?'); //removes hash (to avoid getting hash query)
var queryString = /\?[a-zA-Z0-9\=\&\%\$\-\_\.\+\!\*\'\(\)\,]+/.exec(url); //valid chars according to: http://www.ietf.org/rfc/rfc1738.txt
return (queryString)? decodeURIComponent(queryString[0]) : '';
}
Expand Down
10 changes: 10 additions & 0 deletions tests/spec/queryString/spec-getQuery.js
Expand Up @@ -6,6 +6,16 @@ define(['mout/queryString/getQuery'], function (getQuery) {
var q = getQuery("http://example.com/?foo=bar&a=123&b=false&c=null");
expect( q ).toBe( '?foo=bar&a=123&b=false&c=null' );
});

it('should extract query string from url with hash', function () {
var q = getQuery("http://example.com/#/with-hash/?foo=bar&a=123&b=false&c=null");
expect( q ).toBe( '?foo=bar&a=123&b=false&c=null' );
});

it('should extract first group of the query string when has multiple queries', function () {
var q = getQuery("http://example.com/?foo=bar&a=123#/hash?b=false&c=null");
expect( q ).toBe( '?foo=bar&a=123' );
});
});

});