comparison mercurial/manifest.py @ 3607:f4c9bb4ad7b1

issue352: disallow '\n' and '\r' in filenames (dirstate and manifest)
author Benoit Boissinot <benoit.boissinot@ens-lyon.org>
date Wed, 01 Nov 2006 17:56:55 +0100
parents 53e843840349
children abaee83ce0a6
comparison
equal deleted inserted replaced
3606:f8589028a7fa 3607:f4c9bb4ad7b1
136 else: 136 else:
137 del addlist[start:end] 137 del addlist[start:end]
138 return "".join([struct.pack(">lll", d[0], d[1], len(d[2])) + d[2] \ 138 return "".join([struct.pack(">lll", d[0], d[1], len(d[2])) + d[2] \
139 for d in x ]) 139 for d in x ])
140 140
141 def checkforbidden(f):
142 if '\n' in f or '\r' in f:
143 raise RevlogError(_("'\\n' and '\\r' disallowed in filenames"))
144
141 # if we're using the listcache, make sure it is valid and 145 # if we're using the listcache, make sure it is valid and
142 # parented by the same node we're diffing against 146 # parented by the same node we're diffing against
143 if not changed or not self.listcache or not p1 or \ 147 if not changed or not self.listcache or not p1 or \
144 self.mapcache[0] != p1: 148 self.mapcache[0] != p1:
145 files = map.keys() 149 files = map.keys()
146 files.sort() 150 files.sort()
151
152 for f in files:
153 checkforbidden(f)
147 154
148 # if this is changed to support newlines in filenames, 155 # if this is changed to support newlines in filenames,
149 # be sure to check the templates/ dir again (especially *-raw.tmpl) 156 # be sure to check the templates/ dir again (especially *-raw.tmpl)
150 text = ["%s\000%s%s\n" % (f, hex(map[f]), map.flags(f)) for f in files] 157 text = ["%s\000%s%s\n" % (f, hex(map[f]), map.flags(f)) for f in files]
151 self.listcache = array.array('c', "".join(text)) 158 self.listcache = array.array('c', "".join(text))
152 cachedelta = None 159 cachedelta = None
153 else: 160 else:
154 addlist = self.listcache 161 addlist = self.listcache
155 162
163 for f in changed[0]:
164 checkforbidden(f)
156 # combine the changed lists into one list for sorting 165 # combine the changed lists into one list for sorting
157 work = [[x, 0] for x in changed[0]] 166 work = [[x, 0] for x in changed[0]]
158 work[len(work):] = [[x, 1] for x in changed[1]] 167 work[len(work):] = [[x, 1] for x in changed[1]]
159 work.sort() 168 work.sort()
160 169