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

After dispatching an action, npm module @respond_framework/rudy/es/utils/parseSearch.js truncates the query string(12a) starting with number to only number(12)) #80

Open
anil-moharana opened this issue Sep 25, 2020 · 1 comment

Comments

@anil-moharana
Copy link

anil-moharana commented Sep 25, 2020

After dispatching an action like this
dispatch({
type: 'SEARCH',
query: {
q
}
})
This parseSearch.js file truncates the querystring 123abc to 123 only.
For all other strings it works fine.

@respond_framework/rudy/es/utils/matchUrl.js

function call:
var parseSearch = function parseSearch(search, route, opts) {
if (queries[search]) return queries[search];
var parse = route.parseSearch || opts.parseSearch;
queries[search] = parse(search);
return queries[search];
};

@respond_framework/rudy/es/utils/parseSearch.js

import qs from 'qs';
export default (function (search) {
return qs.parse(search, {
decoder: decoder
});
});

var decoder = function decoder(str, decode) { //str=12a
return isNumber(str) ? Number.parseFloat(str) : decode(str); // returns 12 instead of 12a
};

var isNumber = function isNumber(str) {
return !Number.isNaN(Number.parseFloat(str));// returns true for 12a which should be false
};

@anil-moharana anil-moharana reopened this Sep 25, 2020
@anil-moharana anil-moharana changed the title npm module @respond_framework/rudy/es/utils/parseSearch.js truncates the query string(12a) starting with number to only number(12)) After dispatching an action, npm module @respond_framework/rudy/es/utils/parseSearch.js truncates the query string(12a) starting with number to only number(12)) Sep 27, 2020
@kylebuildsstuff
Copy link

kylebuildsstuff commented Jan 10, 2022

Came across the same problem and managed to fix it using patch-package, replacing:

!Number.isNaN(Number.parseFloat(str))

with

!Number.isNaN(Number(str))

Edit:

Found this snippet is better:

!Number.isNaN(parseFloat(str)) && !Number.isNaN(str - 0)

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

No branches or pull requests

2 participants