Skip to content

Commit 17b4d25

Browse files
committed
Hardened some configuration constraints.
1 parent e5d4d97 commit 17b4d25

File tree

2 files changed

+32
-9
lines changed

2 files changed

+32
-9
lines changed

Changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,5 @@ __*Why "v3.0.0" instead of "v1.0.0?"*__ Prior to phpMussel v3, the "phpMussel Co
113113
[2022.09.26; Maikuolan]: Configuration multiline support added (necessary in order to properly facilitate the custom headers/footers feature introduced earlier today).
114114

115115
[2022.10.22; Maikuolan]: Added L10N for Persian/Farsi.
116+
117+
[2022.10.25; Maikuolan]: Hardened some configuration constraints.

src/FrontEnd.php

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* License: GNU/GPLv2
99
* @see LICENSE.txt
1010
*
11-
* This file: Front-end handler (last modified: 2022.09.26).
11+
* This file: Front-end handler (last modified: 2022.10.25).
1212
*/
1313

1414
namespace phpMussel\FrontEnd;
@@ -1436,14 +1436,32 @@ public function view(string $Page = ''): void
14361436
$ThisDir['DirLangKey'],
14371437
empty($this->Loader->ConfigurationDefaults[$CatKey][$DirKey]['default']) ? 'false' : 'true'
14381438
);
1439-
} elseif (in_array($DirValue['type'], ['float', 'int'], true)) {
1439+
} elseif ($DirValue['type'] === 'float' || $DirValue['type'] === 'int') {
1440+
$ThisDir['FieldAppend'] = '';
1441+
if (isset($DirValue['step'])) {
1442+
$ThisDir['FieldAppend'] .= ' step="' . $DirValue['step'] . '"';
1443+
}
1444+
$ThisDir['FieldAppend'] .= $ThisDir['Trigger'];
1445+
if ($DirValue['type'] === 'int') {
1446+
$ThisDir['FieldAppend'] .= ' inputmode="numeric"';
1447+
if (isset($DirValue['pattern'])) {
1448+
$ThisDir['FieldAppend'] .= ' pattern="' . $DirValue['pattern'] . '"';
1449+
} else {
1450+
$ThisDir['FieldAppend'] .= (!isset($DirValue['min']) || $DirValue['min'] < 0) ? ' pattern="^-?\d*$"' : ' pattern="^\d*$"';
1451+
}
1452+
} elseif (isset($DirValue['pattern'])) {
1453+
$ThisDir['FieldAppend'] .= ' pattern="' . $DirValue['pattern'] . '"';
1454+
}
1455+
foreach (['min', 'max'] as $ThisDir['ParamTry']) {
1456+
if (isset($DirValue[$ThisDir['ParamTry']])) {
1457+
$ThisDir['FieldAppend'] .= ' ' . $ThisDir['ParamTry'] . '="' . $DirValue[$ThisDir['ParamTry']] . '"';
1458+
}
1459+
}
14401460
$ThisDir['FieldOut'] = sprintf(
1441-
'<input type="number" name="%1$s" id="%1$s_field" value="%2$s"%3$s%4$s%5$s />',
1461+
'<input type="number" name="%1$s" id="%1$s_field" value="%2$s"%3$s />',
14421462
$ThisDir['DirLangKey'],
14431463
$this->Loader->Configuration[$CatKey][$DirKey],
1444-
(isset($DirValue['step']) ? ' step="' . $DirValue['step'] . '"' : ''),
1445-
$ThisDir['Trigger'],
1446-
($DirValue['type'] === 'int' ? ' inputmode="numeric"' : '')
1464+
$ThisDir['FieldAppend']
14471465
);
14481466
if (isset($this->Loader->ConfigurationDefaults[$CatKey][$DirKey]['default'])) {
14491467
$ThisDir['Reset'] .= sprintf(
@@ -1470,12 +1488,15 @@ public function view(string $Page = ''): void
14701488
);
14711489
}
14721490
} else {
1491+
$ThisDir['FieldAppend'] = $ThisDir['autocomplete'] . $ThisDir['Trigger'];
1492+
if (isset($DirValue['pattern'])) {
1493+
$ThisDir['FieldAppend'] .= ' pattern="' . $DirValue['pattern'] . '"';
1494+
}
14731495
$ThisDir['FieldOut'] = sprintf(
1474-
'<input type="text" name="%1$s" id="%1$s_field" value="%2$s"%3$s%4$s />',
1496+
'<input type="text" name="%1$s" id="%1$s_field" value="%2$s"%3$s />',
14751497
$ThisDir['DirLangKey'],
14761498
$this->Loader->Configuration[$CatKey][$DirKey],
1477-
$ThisDir['autocomplete'],
1478-
$ThisDir['Trigger']
1499+
$ThisDir['FieldAppend']
14791500
);
14801501
if (isset($this->Loader->ConfigurationDefaults[$CatKey][$DirKey]['default'])) {
14811502
$ThisDir['Reset'] .= sprintf(

0 commit comments

Comments
 (0)