##// END OF EJS Templates
bookmarks: forbid \0 \r \n : in bookmark names (BC)...
David Soria Parra -
r13425:0fe36c34 default
parent child Browse files
Show More
@@ -7,9 +7,15 b''
7 7
8 8 from mercurial.i18n import _
9 9 from mercurial.node import nullid, nullrev, bin, hex, short
10 from mercurial import encoding
10 from mercurial import encoding, util
11 11 import os
12 12
13 def valid(mark):
14 for c in (':', '\0', '\n', '\r'):
15 if c in mark:
16 return False
17 return True
18
13 19 def read(repo):
14 20 '''Parse .hg/bookmarks file and return a dictionary
15 21
@@ -63,8 +69,14 b' def write(repo):'
63 69
64 70 if repo._bookmarkcurrent not in refs:
65 71 setcurrent(repo, None)
72 for mark in refs.keys():
73 if not valid(mark):
74 raise util.Abort(_("bookmark '%s' contains illegal "
75 "character" % mark))
76
66 77 wlock = repo.wlock()
67 78 try:
79
68 80 file = repo.opener('bookmarks', 'w', atomictemp=True)
69 81 for refspec, node in refs.iteritems():
70 82 file.write("%s %s\n" % (hex(node), encoding.fromlocal(refspec)))
@@ -97,6 +109,10 b' def setcurrent(repo, mark):'
97 109 return
98 110 if mark not in refs:
99 111 mark = ''
112 if not valid(mark):
113 raise util.Abort(_("bookmark '%s' contains illegal "
114 "character" % mark))
115
100 116 wlock = repo.wlock()
101 117 try:
102 118 file = repo.opener('bookmarks.current', 'w', atomictemp=True)
@@ -212,3 +212,10 b' bookmark name with whitespace only'
212 212 $ hg bookmark ' '
213 213 abort: bookmark names cannot consist entirely of whitespace
214 214 [255]
215
216 invalid bookmark
217
218 $ hg bookmark 'foo:bar'
219 abort: bookmark 'foo:bar' contains illegal character
220 [255]
221
General Comments 0
You need to be logged in to leave comments. Login now