mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-29 00:38:11 -05:00
Allow 2-character language subreddits to be added to multis.
This commit is contained in:
@@ -61,7 +61,7 @@ from r2.lib.base import abort
|
||||
|
||||
|
||||
multi_sr_data_json_spec = VValidatedJSON.Object({
|
||||
'name': VSubredditName('name'),
|
||||
'name': VSubredditName('name', allow_language_srs=True),
|
||||
})
|
||||
|
||||
|
||||
@@ -314,7 +314,7 @@ class MultiApiController(RedditController, OAuth2ResourceController):
|
||||
VUser(),
|
||||
VModhash(),
|
||||
multi=VMultiByPath("multipath", require_edit=True),
|
||||
sr_name=VSubredditName('srname'),
|
||||
sr_name=VSubredditName('srname', allow_language_srs=True),
|
||||
data=VValidatedJSON("model", multi_sr_data_json_spec),
|
||||
)
|
||||
def PUT_multi_subreddit(self, multi, sr_name, data):
|
||||
|
||||
@@ -512,14 +512,22 @@ class VCssMeasure(Validator):
|
||||
return value if value and self.measure.match(value) else ''
|
||||
|
||||
subreddit_rx = re.compile(r"\A[A-Za-z0-9][A-Za-z0-9_]{2,20}\Z")
|
||||
language_subreddit_rx = re.compile(r"\A[a-z]{2}\Z")
|
||||
|
||||
def chksrname(x, allow_language_srs=False):
|
||||
if not x:
|
||||
return None
|
||||
|
||||
def chksrname(x):
|
||||
#notice the space before reddit.com
|
||||
if x in ('friends', 'all', ' reddit.com'):
|
||||
return False
|
||||
|
||||
try:
|
||||
return str(x) if x and subreddit_rx.match(x) else None
|
||||
valid = subreddit_rx.match(x)
|
||||
if allow_language_srs:
|
||||
valid = valid or language_subreddit_rx.match(x)
|
||||
|
||||
return str(x) if valid else None
|
||||
except UnicodeEncodeError:
|
||||
return None
|
||||
|
||||
@@ -611,11 +619,12 @@ class VSelfText(VMarkdown):
|
||||
max_length = property(get_max_length, set_max_length)
|
||||
|
||||
class VSubredditName(VRequired):
|
||||
def __init__(self, item, *a, **kw):
|
||||
def __init__(self, item, allow_language_srs=False, *a, **kw):
|
||||
VRequired.__init__(self, item, errors.BAD_SR_NAME, *a, **kw)
|
||||
self.allow_language_srs = allow_language_srs
|
||||
|
||||
def run(self, name):
|
||||
name = chksrname(name)
|
||||
name = chksrname(name, self.allow_language_srs)
|
||||
if not name:
|
||||
self.set_error(self._error, code=400)
|
||||
return name
|
||||
|
||||
Reference in New Issue
Block a user