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

balOfferNumber is piping invalid input values #388

Closed
predrag-arsic opened this issue Nov 1, 2021 · 2 comments
Closed

balOfferNumber is piping invalid input values #388

predrag-arsic opened this issue Nov 1, 2021 · 2 comments
Labels
🐛 bug Something isn't working

Comments

@predrag-arsic
Copy link
Contributor

When an invalid string value for offer number, the one that has leading or trailing whitespaces ( " 501234567" or "501234567 " ), is pasted inside the input field which has binded [value] property of the <bal-input> form still considers this string as invalid, as it should because it's invalid to regex matching, but it is properly piped, giving the user right output in the input field (for mentioned examples it is "50/1.234.567"). This gives the user the wrong sense that the data provided are correct, though they are not.

As I've investigated a bit, the problem comes down to using parseInt inside balOfferNumber because this will parse to number regardless of whitespaces. Maybe we should reconsider including the check for the length of the string before doing anything else in this function?

@predrag-arsic predrag-arsic added the 🐛 bug Something isn't working label Nov 1, 2021
@hirsch88
Copy link
Member

Hi, @predrag-arsic

Thanks for creating the issue.
In the version 2.0.0 the pipes are now in web-app-utils.

Could you please create there a pr.

  1. First add a test with that issue.

Maybe we could use regex like that there.

var pipeValue = ' 501234567'
var cleaned = ('' + pipeValue).replace(/\D/g, '').trim();
var match = cleaned.match(/^(\d{2})(\d{1})(\d{3})(\d{3})$/);
if (match) {
    return match[1] + '/' + match[2] + '.' + match[3] + '.' + match[4]
}
return ''

Cheers,
Gery

@predrag-arsic
Copy link
Contributor Author

Moved to web-app-utils

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants