Replaced : with , in recentclicks cookie.

Make reddit_base use the same fullname validating code as GET_widget.
Don't update recentclicks cookie when clicking on subreddits.
Prefix non-logged-in cookies with a _ in JS to match what we do on the server side.
This commit is contained in:
spez
2009-06-03 13:46:43 -07:00
parent 9c1b159614
commit 56f3a4822e
4 changed files with 22 additions and 18 deletions

View File

@@ -140,7 +140,7 @@ def set_user_cookie(name, val):
uname = c.user.name if c.user_is_loggedin else ""
c.cookies[uname + '_' + name] = Cookie(value = val)
valid_click_cookie = re.compile(r'(:?t[0-9]+_[a-zA-Z0-9]+)+').match
valid_click_cookie = fullname_regex(Link, True).match
def set_recent_clicks():
c.recent_clicks = []
if not c.user_is_loggedin:
@@ -149,11 +149,11 @@ def set_recent_clicks():
click_cookie = read_user_cookie('recentclicks')
if click_cookie:
if valid_click_cookie(click_cookie):
names = [ x for x in UniqueIterator(click_cookie.split(':')) if x ]
names = [ x for x in UniqueIterator(click_cookie.split(',')) if x ]
if len(click_cookie) > 1000:
names = names[:20]
set_user_cookie('recentclicks', ':'.join(names))
set_user_cookie('recentclicks', ','.join(names))
#eventually this will look at the user preference
names = names[:5]
c.recent_clicks = Link._by_fullname(names, data = True,

View File

@@ -349,19 +349,22 @@ class VAccountByName(VRequired):
except NotFound: pass
return self.error()
def fullname_regex(thing_cls = None, multiple = False):
pattern = Thing._type_prefix
if thing_cls:
pattern += utils.to36(thing_cls._type_id)
else:
pattern += r"[0-9a-z]+"
pattern += r"_[0-9a-z]+"
if multiple:
pattern = r"(%s *,? *)+" % pattern
return re.compile(r"^" + pattern + r"$")
class VByName(Validator):
splitter = re.compile('[ ,]+')
def __init__(self, param, thing_cls = None, multiple = False,
error = errors.NO_THING_ID, **kw):
pattern = Thing._type_prefix
if thing_cls:
pattern += utils.to36(thing_cls._type_id)
else:
pattern += r"[0-9a-z]+"
pattern += r"_[0-9a-z]+"
if multiple:
pattern = r"(%s *,? *)+" % pattern
self.re = re.compile(r"^" + pattern + r"$")
self.re = fullname_regex(thing_cls, multiple)
self.multiple = multiple
self._error = error

View File

@@ -600,7 +600,7 @@ $.default_cookie_domain = function(domain) {
return default_cookie_domain;
};
var cookie_name_prefix = "";
var cookie_name_prefix = "_";
$.cookie_name_prefix = function(name) {
if($.defined(name))
cookie_name_prefix = name + "_";

View File

@@ -473,12 +473,12 @@ function add_thing_id_to_cookie(id, cookie_name) {
return;
}
cookie.data = id + ':' + cookie.data;
cookie.data = id + ',' + cookie.data;
if(cookie.data.length > 1000) {
var fullnames = cookie.data.split(':');
var fullnames = cookie.data.split(',');
fullnames = $.uniq(fullnames, 20);
cookie.data = fullnames.join(':');
cookie.data = fullnames.join(',');
}
$.cookie_write(cookie);
@@ -487,7 +487,7 @@ function add_thing_id_to_cookie(id, cookie_name) {
function clicked_items() {
var cookie = $.cookie_read('recentclicks');
if(cookie && cookie.data) {
var fullnames = cookie.data.split(":");
var fullnames = cookie.data.split(",");
/* don't return empty ones */
for(var i=fullnames.length-1; i >= 0; i--) {
if(!fullnames[i] || !fullnames[i].length) {
@@ -533,7 +533,8 @@ function updateEventHandlers(thing) {
.filter(":visible").trigger("onshow");
/* click on a title.. */
$(thing).find("a.title, a.comments").mousedown(function() {
$(thing).filter(".link, .linkcompressed")
.find("a.title, a.comments").mousedown(function() {
/* the site is either stored in the sr dict, or we are on
* an sr and it is the current one */
var sr = reddit.sr[$(this).thing_id()] || reddit.cur_site;