mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-24 16:30:27 +08:00
Merge pull request #17983 from mvdbeek/fix_LengthValidator
[24.0] Fix `LengthValidator` if no value passed
This commit is contained in:
@@ -186,7 +186,9 @@ class LengthValidator(InRangeValidator):
|
||||
super().__init__(message, range_min=length_min, range_max=length_max, negate=negate)
|
||||
|
||||
def validate(self, value, trans=None):
|
||||
super().validate(len(value), trans)
|
||||
if value is None:
|
||||
raise ValueError("No value provided")
|
||||
super().validate(len(value) if value else 0, trans)
|
||||
|
||||
|
||||
class DatasetOkValidator(Validator):
|
||||
|
||||
@@ -186,6 +186,14 @@ class TestParameterValidation(BaseParameterTestCase):
|
||||
p.validate("bar")
|
||||
p.validate("f")
|
||||
p.validate("foobarbaz")
|
||||
p = self._parameter_for(
|
||||
xml="""
|
||||
<param name="blah" type="text" optional="false">
|
||||
<validator type="length" min="2" max="8"/>
|
||||
</param>"""
|
||||
)
|
||||
with self.assertRaisesRegex(ValueError, "No value provided"):
|
||||
p.validate(None)
|
||||
|
||||
def test_InRangeValidator(self):
|
||||
p = self._parameter_for(
|
||||
|
||||
Reference in New Issue
Block a user