mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-04 22:57:40 +08:00
Simplified Regex usage in JS
Follows 70752b0fc1dde9a32d3565759d77072d3187f4eb
This commit is contained in:
@ -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'}));
|
||||||
|
|||||||
@ -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 {
|
||||||
|
|||||||
Reference in New Issue
Block a user