tags: don't allow tags to begin with a '/'.

Disallow tags from starting with a '/' character. This is so that tag
abbreviations in autocomplete, which start with a '/', don't conflict
with regular tags.

Also disallow some other punctuation characters: `%{})]. Currently no
tags start with these characters. This is to reserve other special
characters in case we need them for other future syntax extensions.
This commit is contained in:
evazion
2020-12-17 13:17:55 -06:00
parent 7a87225ac8
commit 1809f67b2b
3 changed files with 9 additions and 16 deletions

View File

@@ -7,12 +7,8 @@ class TagNameValidator < ActiveModel::EachValidator
record.errors.add(attribute, "'#{value}' cannot contain asterisks ('*')")
when /,/
record.errors.add(attribute, "'#{value}' cannot contain commas (',')")
when /\A~/
record.errors.add(attribute, "'#{value}' cannot begin with a tilde ('~')")
when /\A-/
record.errors.add(attribute, "'#{value}' cannot begin with a dash ('-')")
when /\A_/
record.errors.add(attribute, "'#{value}' cannot begin with an underscore")
when /\A[-~_`%){}\]\/]/
record.errors.add(attribute, "'#{value}' cannot begin with a '#{value[0]}'")
when /_\z/
record.errors.add(attribute, "'#{value}' cannot end with an underscore")
when /__/