Skip to content

Commit

Permalink
fix(calendar(js)): escape CSS selector names
Browse files Browse the repository at this point in the history
SOGo uses the name of calendar categories verbatim to construct a CSS
selector without escaping characters such as "/". This patch ensures
those selector names are properly escaped so calendar categories
applied to a calendar event match the according selector and appear
in the correct color.

This patch makes use of the CSS escape API which is supported by all
major browsers. See https://caniuse.com/mdn-api_css_escape.

Also see https://mathiasbynens.be/notes/css-escapes.
  • Loading branch information
leonklingele committed May 10, 2023
1 parent 67cf3c0 commit 5c94461
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
19 changes: 19 additions & 0 deletions UI/WebServerResources/js/Common/cssescape.filter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* -*- Mode: javascript; indent-tabs-mode: nil; c-basic-offset: 2 -*- */

/**
* @type {angular.Module}
*/
(function () {
'use strict';

/**
* @ngInject
*/
cssEscape.$inject = ['$window'];
function cssEscape($window) {
return $window.CSS.escape;
}

angular.module('SOGo.Common')
.filter('cssEscape', cssEscape);
})();
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
template: [
'<style type="text/css">',
/* Background color */
' .bg-category{{ ngModel.id }} {',
' .bg-category{{ ngModel.id | cssEscape }} {',
' background-color: {{ ngModel.color }} !important;',
' }',
/* Border color */
' .bdr-category{{ ngModel.id }} {',
' .bdr-category{{ ngModel.id | cssEscape }} {',
' border-color: {{ ngModel.color }} !important;',
' }',
'</style>'
Expand Down

0 comments on commit 5c94461

Please sign in to comment.