Explorar el Código

Added example and handled invalid ranges gracefully

Saria Hajjar hace 6 años
padre
commit
396bb28967
Se han modificado 1 ficheros con 4 adiciones y 0 borrados
  1. 4 0
      netbox/utilities/forms.py

+ 4 - 0
netbox/utilities/forms.py

@@ -65,6 +65,9 @@ def parse_alphanumeric_range(string):
                 values.append(begin)
             # Range-based
             else:
+                # Not a valid range (more than a single character)
+                if not len(begin) == len(end) == 1:
+                    raise forms.ValidationError('Range "{}" is invalid.'.format(dash_range))
                 for n in list(range(ord(begin), ord(end) + 1)):
                     values.append(chr(n))
     return values
@@ -486,6 +489,7 @@ class ExpandableNameField(forms.CharField):
                              'Mixed cases and types within a single range are not supported.<br />' \
                              'Examples:<ul><li><code>ge-0/0/[0-23,25,30]</code></li>' \
                              '<li><code>e[0-3][a-d,f]</code></li>' \
+                             '<li><code>[xe,ge]-0/0/0</code></li>' \
                              '<li><code>e[0-3,a-d,f]</code></li></ul>'
 
     def to_python(self, value):