Input limit on key name
server has checked the input parameters,
Key names can only contain alphanumeric characters,
underscores, periods, colons and hyphens
# License for the specific language governing permissions and limitations
# under the License.
+import re
+
from django.urls import reverse
from django.utils.translation import ugettext_lazy as _
@@ -20,8 +22,16 @@ from horizon import forms
from horizon import messages
+KEY_NAME_REGEX = re.compile(r"^[a-zA-Z0-9-_.:]+$", re.UNICODE)
+KEY_ERROR_MESSAGES = {
+ 'invalid': _('Key names can only contain alphanumeric characters, '
+ 'underscores, periods, colons and hyphens')}
+
+
class CreateExtraSpec(forms.SelfHandlingForm):
- key = forms.CharField(max_length=255, label=_("Key"))
+ key = forms.RegexField(max_length=255, label=_("Key"),
+ regex=KEY_NAME_REGEX,
+ error_messages=KEY_ERROR_MESSAGES)
value = forms.CharField(max_length=255, label=_("Value"))
def handle(self, request, data):
