Drop extra whitespace in title on suggest/submit

This commit is contained in:
Chad Birch
2013-03-28 15:41:39 -06:00
parent 053ebafcc7
commit 89ff4e6cb2
2 changed files with 9 additions and 1 deletions

View File

@@ -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:

View File

@@ -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')