Simplified Regex usage in JS

Follows 70752b0fc1dde9a32d3565759d77072d3187f4eb
This commit is contained in:
SilverFire - Dmitry Naumenko
2016-11-05 21:07:05 +02:00
parent 0c33c9d075
commit 6f4c52a53d
2 changed files with 5 additions and 10 deletions

View File

@ -208,8 +208,7 @@ window.yii = (function ($) {
var newForm = !$form.length; var newForm = !$form.length;
if (newForm) { if (newForm) {
var regexp = /(^\/|:\/\/)/; if (!action || !/(^\/|:\/\/)/.test(action)) {
if (!action || !regexp.test(action)) {
action = window.location.href; action = window.location.href;
} }
$form = $('<form/>', {method: method, action: action}); $form = $('<form/>', {method: method, action: action});
@ -217,13 +216,11 @@ window.yii = (function ($) {
if (target) { if (target) {
$form.attr('target', target); $form.attr('target', target);
} }
regexp = /(get|post)/i; if (!/(get|post)/i.test(method)) {
if (!regexp.test(method)) {
$form.append($('<input/>', {name: '_method', value: method, type: 'hidden'})); $form.append($('<input/>', {name: '_method', value: method, type: 'hidden'}));
method = 'POST'; method = 'POST';
} }
regexp = /(get|head|options)/i; if (!/(get|head|options)/i.test(method)) {
if (!regexp.test(method)) {
var csrfParam = pub.getCsrfParam(); var csrfParam = pub.getCsrfParam();
if (csrfParam) { if (csrfParam) {
$form.append($('<input/>', {name: csrfParam, value: pub.getCsrfToken(), type: 'hidden'})); $form.append($('<input/>', {name: csrfParam, value: pub.getCsrfToken(), type: 'hidden'}));

View File

@ -225,16 +225,14 @@ yii.validation = (function ($) {
return; return;
} }
var regexp = /:\/\//; if (options.defaultScheme && !/:\/\//.test(value)) {
if (options.defaultScheme && !regexp.test(value)) {
value = options.defaultScheme + '://' + value; value = options.defaultScheme + '://' + value;
} }
var valid = true; var valid = true;
if (options.enableIDN) { if (options.enableIDN) {
regexp = /^([^:]+):\/\/([^\/]+)(.*)$/; var matches = /^([^:]+):\/\/([^\/]+)(.*)$/.exec(value);
matches = regexp.exec(value);
if (matches === null) { if (matches === null) {
valid = false; valid = false;
} else { } else {