diff --git a/r2/r2/controllers/api.py b/r2/r2/controllers/api.py index ccc6d2002..f551564d9 100755 --- a/r2/r2/controllers/api.py +++ b/r2/r2/controllers/api.py @@ -75,6 +75,7 @@ import csv from collections import defaultdict from datetime import datetime, timedelta import hashlib +import re import urllib import urllib2 @@ -377,8 +378,12 @@ class ApiController(RedditController, OAuth2ResourceController): if not c.user.gold or not hasattr(request.post, 'sendreplies'): sendreplies = kind == 'self' + # get rid of extraneous whitespace in the title + cleaned_title = re.sub(r'\s+', ' ', request.post.title, flags=re.UNICODE) + cleaned_title = cleaned_title.strip() + # well, nothing left to do but submit it - l = Link._submit(request.post.title, url if kind == 'link' else 'self', + l = Link._submit(cleaned_title, url if kind == 'link' else 'self', c.user, sr, ip, spam=c.user._spam, sendreplies=sendreplies) if banmsg: diff --git a/r2/r2/lib/utils/utils.py b/r2/r2/lib/utils/utils.py index 6c58c4a05..13c903a55 100644 --- a/r2/r2/lib/utils/utils.py +++ b/r2/r2/lib/utils/utils.py @@ -310,6 +310,9 @@ def extract_title(data): if to_trim and to_trim.end() < len(title) / 2: title = title[:-(to_trim.end())] + # get rid of extraneous whitespace in the title + title = re.sub(r'\s+', ' ', title, flags=re.UNICODE) + return title.encode('utf-8').strip() valid_schemes = ('http', 'https', 'ftp', 'mailto')