Stop allowing accented characters in tags (#9006)
* Stop allowing accented characters in tags This commit will add strict frontend and backend validation for tags disallowing accented characters. * Update tags validation error message * Add more character sets to tag validation spec
This commit is contained in:
parent
db17e98804
commit
83ba6b64c9
3 changed files with 22 additions and 1 deletions
|
|
@ -449,6 +449,7 @@ class Tags extends Component {
|
|||
onKeyDown={this.handleKeyDown}
|
||||
onBlur={this.handleFocusChange}
|
||||
onFocus={onFocus}
|
||||
pattern={`${LETTERS_NUMBERS}`}
|
||||
/>
|
||||
{searchResultsHTML}
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -82,7 +82,10 @@ class Tag < ActsAsTaggableOn::Tag
|
|||
|
||||
def validate_name
|
||||
errors.add(:name, "is too long (maximum is 30 characters)") if name.length > 30
|
||||
errors.add(:name, "contains non-alphanumeric characters") unless name.match?(/\A[[:alnum:]]+\z/)
|
||||
# [:alnum:] is not used here because it supports diacritical characters.
|
||||
# If we decide to allow diacritics in the future, we should replace the
|
||||
# following regex with [:alnum:].
|
||||
errors.add(:name, "contains non-ASCII characters") unless name.match?(/\A[[a-z0-9]]+\z/i)
|
||||
end
|
||||
|
||||
def mod_chat_channel
|
||||
|
|
|
|||
|
|
@ -46,6 +46,23 @@ RSpec.describe Tag, type: :model do
|
|||
tag.name = nil
|
||||
expect(tag).not_to be_valid
|
||||
end
|
||||
|
||||
it "fails validations if name uses non-ASCII characters" do
|
||||
tag.name = "مرحبا"
|
||||
expect(tag).not_to be_valid
|
||||
|
||||
tag.name = "你好"
|
||||
expect(tag).not_to be_valid
|
||||
|
||||
tag.name = "Cześć"
|
||||
expect(tag).not_to be_valid
|
||||
|
||||
tag.name = "♩ ♪ ♫ ♬ ♭ ♮ ♯"
|
||||
expect(tag).not_to be_valid
|
||||
|
||||
tag.name = "Test™"
|
||||
expect(tag).not_to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
describe "alias_for" do
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue