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

View File

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