comparison mercurial/templatefilters.py @ 25778:3a33412792f1

templates: introduce revescape filter for escaping symbolic revisions There needs to be a way to escape symbolic revisions containing forward slashes, but urlescape filter doesn't escape slashes at all (in fact, it is used in places where forward slashes must be preserved). The filter considers @ to be safe just for bookmarks like @ and @default to look good in urls.
author Anton Shestakov <av6@dwimlabs.net>
date Sun, 12 Jul 2015 16:47:56 +0800
parents c54248bbe023
children 1245049da5f3
comparison
equal deleted inserted replaced
25777:1c2a8db33b8f 25778:3a33412792f1
281 if f != -1: 281 if f != -1:
282 return author[:f].strip(' "').replace('\\"', '"') 282 return author[:f].strip(' "').replace('\\"', '"')
283 f = author.find('@') 283 f = author.find('@')
284 return author[:f].replace('.', ' ') 284 return author[:f].replace('.', ' ')
285 285
286 def revescape(text):
287 """:revescape: Any text. Escapes all "special" characters, except @.
288 Forward slashes are escaped twice to prevent web servers from prematurely
289 unescaping them. For example, "@foo bar/baz" becomes "@foo%20bar%252Fbaz".
290 """
291 return urllib.quote(text, safe='/@').replace('/', '%252F')
292
286 def rfc3339date(text): 293 def rfc3339date(text):
287 """:rfc3339date: Date. Returns a date using the Internet date format 294 """:rfc3339date: Date. Returns a date using the Internet date format
288 specified in RFC 3339: "2009-08-18T13:00:13+02:00". 295 specified in RFC 3339: "2009-08-18T13:00:13+02:00".
289 """ 296 """
290 return util.datestr(text, "%Y-%m-%dT%H:%M:%S%1:%2") 297 return util.datestr(text, "%Y-%m-%dT%H:%M:%S%1:%2")
400 "lower": lower, 407 "lower": lower,
401 "nonempty": nonempty, 408 "nonempty": nonempty,
402 "obfuscate": obfuscate, 409 "obfuscate": obfuscate,
403 "permissions": permissions, 410 "permissions": permissions,
404 "person": person, 411 "person": person,
412 "revescape": revescape,
405 "rfc3339date": rfc3339date, 413 "rfc3339date": rfc3339date,
406 "rfc822date": rfc822date, 414 "rfc822date": rfc822date,
407 "short": short, 415 "short": short,
408 "shortbisect": shortbisect, 416 "shortbisect": shortbisect,
409 "shortdate": shortdate, 417 "shortdate": shortdate,