From 68f101b0158716c286fc73ed8d4e11993736bc2b Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Fri, 26 Mar 2021 14:25:48 +0100 Subject: [PATCH] RoleForm: Don't let privilege labels break on dashes --- application/forms/Security/RoleForm.php | 56 ++++++++++++++++--------- public/css/icinga/main.less | 4 ++ 2 files changed, 40 insertions(+), 20 deletions(-) diff --git a/application/forms/Security/RoleForm.php b/application/forms/Security/RoleForm.php index 4afd48b8c..ff44e820f 100644 --- a/application/forms/Security/RoleForm.php +++ b/application/forms/Security/RoleForm.php @@ -171,16 +171,24 @@ class RoleForm extends RepositoryForm 'autosubmit' => isset($spec['isFullPerm']), 'disabled' => $hasFullPerm || $hasAdminPerm ?: null, 'value' => $hasFullPerm || $hasAdminPerm, - 'label' => preg_replace( - // Adds a zero-width char after each slash to help browsers break onto newlines - '~(?$1$2', - $name - ) - ), + 'label' => isset($spec['label']) + ? $spec['label'] + : join('', iterator_to_array(call_user_func(function ($segments) { + foreach ($segments as $segment) { + if ($segment[0] === '/') { + // Adds a zero-width char after each slash to help browsers break onto newlines + yield '/​'; + yield '' . substr($segment, 1) . ''; + } else { + yield '' . $segment . ''; + } + } + }, preg_split( + '~(/[^/]+)~', + $name, + -1, + PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY + )))), 'description' => isset($spec['description']) ? $spec['description'] : $name, 'decorators' => array_merge( array_slice(self::$defaultElementDecorators, 0, 3), @@ -220,16 +228,24 @@ class RoleForm extends RepositoryForm 'text', $elementName, [ - 'label' => preg_replace( - // Adds a zero-width char after each slash to help browsers break onto newlines - '~(?$1$2', - $name - ) - ), + 'label' => isset($spec['label']) + ? $spec['label'] + : join('', iterator_to_array(call_user_func(function ($segments) { + foreach ($segments as $segment) { + if ($segment[0] === '/') { + // Add zero-width char after each slash to help browsers break onto newlines + yield '/​'; + yield '' . substr($segment, 1) . ''; + } else { + yield '' . $segment . ''; + } + } + }, preg_split( + '~(/[^/]+)~', + $name, + -1, + PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY + )))), 'description' => $spec['description'], 'style' => $isUnrestricted ? 'text-decoration:line-through;' : '', 'readonly' => $isUnrestricted ?: null diff --git a/public/css/icinga/main.less b/public/css/icinga/main.less index 15bee5cda..0fe9ed634 100644 --- a/public/css/icinga/main.less +++ b/public/css/icinga/main.less @@ -45,6 +45,10 @@ } } +.no-wrap { + white-space: nowrap; +} + .pull-right { float: right; }