Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14027593
D7274.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D7274.diff
View Options
Index: src/applications/settings/panel/PhabricatorSettingsPanelDisplayPreferences.php
===================================================================
--- src/applications/settings/panel/PhabricatorSettingsPanelDisplayPreferences.php
+++ src/applications/settings/panel/PhabricatorSettingsPanelDisplayPreferences.php
@@ -26,25 +26,36 @@
$pref_monospaced_textareas =
PhabricatorUserPreferences::PREFERENCE_MONOSPACED_TEXTAREAS;
+ $errors = array();
if ($request->isFormPost()) {
$monospaced = $request->getStr($pref_monospaced);
-
- // Prevent the user from doing stupid things.
- $monospaced = preg_replace('/[^a-z0-9 ,"]+/i', '', $monospaced);
+ if (!preg_match('/^[^"]*("[^"]*"[^"]*)*$/', $monospaced) ||
+ preg_match('/[^a-z0-9 ,"-](?=(?:[^"]*"[^"]*")*[^"]*$)/i',
+ $monospaced)) {
+ $errors[] = pht(
+ 'Monospaced Font definition must not contain any mismatched double '.
+ 'quotes, and any font names that do not consist of purely '.
+ 'alphanumeric, space, comma, double quote, or hyphen characters '.
+ 'must be wrapped in double quotes.');
+ } else {
+ $preferences->setPreference($pref_monospaced, $monospaced);
+ }
$preferences->setPreference($pref_titles, $request->getStr($pref_titles));
$preferences->setPreference($pref_editor, $request->getStr($pref_editor));
$preferences->setPreference(
$pref_multiedit,
$request->getStr($pref_multiedit));
- $preferences->setPreference($pref_monospaced, $monospaced);
$preferences->setPreference(
$pref_monospaced_textareas,
$request->getStr($pref_monospaced_textareas));
$preferences->save();
- return id(new AphrontRedirectResponse())
- ->setURI($this->getPanelURI('?saved=true'));
+
+ if (!$errors) {
+ return id(new AphrontRedirectResponse())
+ ->setURI($this->getPanelURI('?saved=true'));
+ }
}
$example_string = <<<EXAMPLE
@@ -138,11 +149,17 @@
->setValue(pht('Save Preferences')));
$error_view = null;
- if ($request->getStr('saved') === 'true') {
+ if (!$errors) {
+ if ($request->getStr('saved') === 'true') {
+ $error_view = id(new AphrontErrorView())
+ ->setTitle(pht('Preferences Saved'))
+ ->setSeverity(AphrontErrorView::SEVERITY_NOTICE)
+ ->setErrors(array(pht('Your preferences have been saved.')));
+ }
+ } else {
$error_view = id(new AphrontErrorView())
- ->setTitle(pht('Preferences Saved'))
- ->setSeverity(AphrontErrorView::SEVERITY_NOTICE)
- ->setErrors(array(pht('Your preferences have been saved.')));
+ ->setTitle(pht('Form Errors'))
+ ->setErrors($errors);
}
$form_box = id(new PHUIObjectBoxView())
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 9, 8:02 AM (6 d, 7 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6762938
Default Alt Text
D7274.diff (2 KB)
Attached To
Mode
D7274: Improve monospaced font preference validation
Attached
Detach File
Event Timeline
Log In to Comment