Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

cleanup pattern input result from non-breaking spaces

Ivan Kuchin14182d9430e9
diff --git a/frontend/src/stimulus/controllers/pattern-input.controller.ts b/frontend/src/stimulus/controllers/pattern-input.controller.ts
index 98ba0fb89cb..c1a36b4ff2a 100644
--- a/frontend/src/stimulus/controllers/pattern-input.controller.ts
+++ b/frontend/src/stimulus/controllers/pattern-input.controller.ts
@@ -47,6 +47,8 @@ const TOKEN_REGEX = /{{([0-9A-Za-z_]+)}}/g;
// A zero-width space character, which is used
// to have a caret position after tokens
const CONTROL_SPACE = '\u200B';
+// A non-breaking space inserted by some browsers to preserve multiple consecutive spaces
+const NON_BREAKING_SPACE = '\u00A0';
export default class PatternInputController extends Controller {
static targets = [
@@ -568,9 +570,11 @@ export default class PatternInputController extends Controller {
}
});
- // remove any padding whitespaces and control spaces,
- // which were used for usability
- return result.trim().replace(new RegExp(CONTROL_SPACE, 'g'), '');
+ // remove any padding whitespaces and control spaces, which were used for
+ // usability, and non-breaking spaces inserted by some browsers
+ return result.trim()
+ .replace(new RegExp(CONTROL_SPACE, 'g'), '')
+ .replace(new RegExp(NON_BREAKING_SPACE, 'g'), ' ');
}
private containsCursor(node:Node):boolean {
diff --git a/spec/features/admin/custom_fields/projects/calculated_value_spec.rb b/spec/features/admin/custom_fields/projects/calculated_value_spec.rb
index 4cf9ca558b8..a9a4fc71dd1 100644
--- a/spec/features/admin/custom_fields/projects/calculated_value_spec.rb
+++ b/spec/features/admin/custom_fields/projects/calculated_value_spec.rb
@@ -124,7 +124,8 @@ RSpec.describe "Edit project custom field calculated value", :js, with_flag: { c
end
it "allows submitting formula by pressing Enter/Return" do
- formula = "2 + 2"
+ # ensure multiple spaces are handled without problems
+ formula = "2 + (1 +1)"
pattern_input = find(:xpath, "//input[@id='custom_field_formula']/parent::div//div[@contenteditable='true']")