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

Url constraint types "http://" with every keystroke #165

Open
benr77 opened this issue Nov 10, 2021 · 3 comments
Open

Url constraint types "http://" with every keystroke #165

benr77 opened this issue Nov 10, 2021 · 3 comments

Comments

@benr77
Copy link
Contributor

benr77 commented Nov 10, 2021

There is a fault with Url constraint. Every time I type a character into a URL field, it prepends http:// so I end up with http://http://http://http://http://http://http://thestartofmyurl etc.

It looks like it is simply because there is no check to see if it's already prefixed http://.

@66Ton99
Copy link
Collaborator

66Ton99 commented Nov 10, 2021

Need more details!

@benr77
Copy link
Contributor Author

benr77 commented Nov 10, 2021

In this constraint:
https://github.com/formapro/JsFormValidatorBundle/blob/master/src/Resources/public/js/constraints/Url.js

There is the following, which checks if the regex is matched, and if it is not, it prefixes the input field's value with http://.

if (!f.isValueEmty(value) && !regexp.test(value)) {
    element.domNode.value = 'http://' + value;
    errors.push(this.message.replace('{{ value }}', FpJsBaseConstraint.formatValue('http://' + value)));
}

What I did forget to mention is my validation is triggered onkeyup, so the validation does not run once on submit, but repeatedly as the user enters the URL.

The above code blindly adds the http:// prefix even if it's already present, so you get multiple prefix strings with every keypress.

I think we need an additional check to see if the prefix already exists, and to not add it if it does. Would you agree? Happy to submit a PR if necessary.

@benr77
Copy link
Contributor Author

benr77 commented Nov 10, 2021

Just submitted #167 to resolve this issue. Let me know what you think.

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