Skip to content

fix for: ReferenceError: v is not defined and improved regex #7133

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

Closed
wants to merge 2 commits into from
Closed

fix for: ReferenceError: v is not defined and improved regex #7133

wants to merge 2 commits into from

Conversation

klict
Copy link
Contributor

@klict klict commented Oct 21, 2016

Hello,

this is a small fix for uncaught ReferenceError: v is not defined ;

You guys were executing function test on variable v but i think you should use variable value since variable v is not defined anywhere.

Also my team leader has improved your the regex for "validate-clean-url" and "validate-url".

credit for regex @redelschaap.

Hello,

this is a small fix for uncaught ReferenceError: v is not defined ;

You guys were executing function test on variable v but i think you should use variable value since variable v is not defined anywhere.

Also my team leader has improved your the regex for "validate-clean-url" and "validate-url".

credit for regex @redelschaap.
@redelschaap
Copy link
Contributor

Note for my improved regex: RFC 1035 section 2.3.4 states that each part of a domain name can contain up to 63 characters, which means also the TLD extension can technically contain 63 charachters. The regex checks whether the DNS part of the URL contains valid parts and is not restricted to the set of TLD's of the original regex.

@sitepodmatt
Copy link

Does this work with http://unicode.org/faq/idn.html?

@redelschaap
Copy link
Contributor

As a matter of fact it doesn't. But I have only improved the DNS part, so neither does the original.

These regex patterns do the trick. Since it's very hard to check for all allowed charachters in the path, query and fragment parts (for example, Chinese or Arabic letters are allowed too), it checks the three parts for whitespace characters only.

@klict Can you please change the regex patterns in your commit?

validate-url

return /^((http|https|ftp):\/\/)(([A-Z0-9][A-Z0-9_-]{1,62}\.)+([A-Z]{2,63}(\.[A-Z]{2,63})?))(:(\d+))?(\/[^\?#\s]*)?(\?[^#\s]*)?(#[^\s]*)?$/i.test(value);

validate-clean-url

return utils.isEmptyNoTrim(value) || /^((http|https|ftp):\/\/)?(([A-Z0-9][A-Z0-9_-]{1,62}\.)+([A-Z]{2,63}(\.[A-Z]{2,63})?))(:(\d+))?(\/[^\?#\s]*)?(\?[^#\s]*)?(#[^\s]*)?$/i.test(value);

Copy link
Contributor

@redelschaap redelschaap left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It didn't check for the path, query and fragment parts correctly, my bad!


},
$.mage.__('Please enter a valid URL. Protocol is required (http://, https:// or ftp://).')
],
"validate-clean-url": [
function(value) {
return utils.isEmptyNoTrim(value) || /^(http|https|ftp):\/\/(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+.(com|org|net|dk|at|us|tv|info|uk|co.uk|biz|se)$)(:(\d+))?\/?/i.test(v) || /^(www)((\.[A-Z0-9][A-Z0-9_-]*)+.(com|org|net|dk|at|us|tv|info|uk|co.uk|biz|se)$)(:(\d+))?\/?/i.test(value);
return utils.isEmptyNoTrim(value) || /^((http|https|ftp):\/\/)?(([A-Z0-9][A-Z0-9_-]{1,62}\.)+([A-Z]{2,63}(\.[A-Z]{2,63})?)$)(:(\d+))?\/?/i.test(value);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It didn't check for the path, query and fragment parts correctly, my bad!

Correct return value:

                 return utils.isEmptyNoTrim(value) || /^((http|https|ftp):\/\/)?(([A-Z0-9][A-Z0-9_-]{1,62}\.)+([A-Z]{2,63}(\.[A-Z]{2,63})?))(:(\d+))?(\/[^\?#\s]*)?(\?[^#\s]*)?(#[^\s]*)?$/i.test(value);

@@ -468,14 +468,14 @@ define([
return true;
}
value = (value || '').replace(/^\s+/, '').replace(/\s+$/, '');
return (/^(http|https|ftp):\/\/(([A-Z0-9]([A-Z0-9_-]*[A-Z0-9]|))(\.[A-Z0-9]([A-Z0-9_-]*[A-Z0-9]|))*)(:(\d+))?(\/[A-Z0-9~](([A-Z0-9_~-]|\.)*[A-Z0-9~]|))*\/?(.*)?$/i).test(value);
return (/^((http|https|ftp):\/\/)(([A-Z0-9][A-Z0-9_-]{1,62}\.)+([A-Z]{2,63}(\.[A-Z]{2,63})?)$)(:(\d+))?\/?/i).test(value);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It didn't check for the path, query and fragment parts correctly, my bad!

Correct return value:

                 return /^((http|https|ftp):\/\/)(([A-Z0-9][A-Z0-9_-]{1,62}\.)+([A-Z]{2,63}(\.[A-Z]{2,63})?))(:(\d+))?(\/[^\?#\s]*)?(\?[^#\s]*)?(#[^\s]*)?$/i.test(value);

@vrann
Copy link
Contributor

vrann commented Mar 25, 2017

@klict please update the code with the latest develop branch

@okorshenko okorshenko self-assigned this Jun 7, 2017
@okorshenko okorshenko added this to the June 2017 milestone Jun 7, 2017
@okorshenko
Copy link
Contributor

Source branch has been removed. Closing this PR.

@okorshenko okorshenko closed this Jun 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants