diff --git a/rest_framework/throttling.py b/rest_framework/throttling.py index ca26549b8..c0100f4fb 100644 --- a/rest_framework/throttling.py +++ b/rest_framework/throttling.py @@ -106,15 +106,15 @@ class SimpleRateThrottle(BaseThrottle): try: num, period = rate.split('/') num_requests = int(num) - # Get rate multiplier value if available - period_mult, _ = re.split('[s|m|h|d]', period, maxsplit=1) - period_char = re.findall('[s|m|h|d]', period)[0] - except ValueError: + period_timescale = re.findall(r'^\d*[s|m|h|d]', period)[0] + period_char = period_timescale[-1] + except (ValueError, IndexError): msg = "Incorrect throttle rate set for '%s' scope" % self.scope raise ImproperlyConfigured(msg) try: - period_mult = int(period_mult) + # Get rate multiplier value if available + period_mult = int(period_timescale[:-1]) except ValueError: period_mult = 1 diff --git a/tests/test_throttling.py b/tests/test_throttling.py index d3614fefc..cf1d5635b 100644 --- a/tests/test_throttling.py +++ b/tests/test_throttling.py @@ -474,11 +474,11 @@ class SimpleRateThrottleTests(TestCase): with pytest.raises(ImproperlyConfigured): SimpleRateThrottle() - SimpleRateThrottle.rate = '100/century' + SimpleRateThrottle.rate = '100/foos' with pytest.raises(ImproperlyConfigured): SimpleRateThrottle() - SimpleRateThrottle.rate = '100/10century' + SimpleRateThrottle.rate = '100/10foos' with pytest.raises(ImproperlyConfigured): SimpleRateThrottle()