Skip to content

Commit 1babb4b

Browse files
committed
Strip ASCII control characters from project identifiers
Add normalizes :identifier with RemoveAsciiControlCharacters to strip characters like newlines, tabs, and backspaces that should never appear in a project identifier.
1 parent f3bfdc3 commit 1babb4b

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

app/models/projects/identifier.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ module Projects::Identifier
3838
included do
3939
extend FriendlyId
4040

41+
normalizes :identifier, with: OpenProject::RemoveAsciiControlCharacters
42+
4143
acts_as_url :name,
4244
url_attribute: :identifier,
4345
sync_url: false, # Don't update identifier when name changes

spec/models/projects/identifier_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@
3131
require "spec_helper"
3232

3333
RSpec.describe Projects::Identifier do
34+
describe "identifier normalization" do
35+
subject { Project.new }
36+
37+
it { is_expected.to normalize(:identifier).from("my\n\x00project\t").to("myproject") }
38+
end
39+
3440
describe "url identifier" do
3541
let(:reserved) do
3642
Rails.application.routes.routes

0 commit comments

Comments
 (0)