# HG changeset patch # User David Soria Parra # Date 1297877805 -3600 # Node ID 0fe36c347c00dc4734f780ec1d079016b69cb3ad # Parent 08f9c587141f807f869a7f134ac848445247ed65 bookmarks: forbid \0 \r \n : in bookmark names (BC) We restrict : to 1. make it easer to convert bookmarks to git branches, 2. use : later for a syntax to push a local bookmark to a remote bookmark of a different name. \0, \n, \r are fobbidden they are used to separate bookmarks in the bookmark file. This change breaks backward compatbility as ':' was an allowed character in previous versions. diff -r 08f9c587141f -r 0fe36c347c00 mercurial/bookmarks.py --- a/mercurial/bookmarks.py Wed Feb 16 04:36:36 2011 +0100 +++ b/mercurial/bookmarks.py Wed Feb 16 18:36:45 2011 +0100 @@ -7,9 +7,15 @@ from mercurial.i18n import _ from mercurial.node import nullid, nullrev, bin, hex, short -from mercurial import encoding +from mercurial import encoding, util import os +def valid(mark): + for c in (':', '\0', '\n', '\r'): + if c in mark: + return False + return True + def read(repo): '''Parse .hg/bookmarks file and return a dictionary @@ -63,8 +69,14 @@ if repo._bookmarkcurrent not in refs: setcurrent(repo, None) + for mark in refs.keys(): + if not valid(mark): + raise util.Abort(_("bookmark '%s' contains illegal " + "character" % mark)) + wlock = repo.wlock() try: + file = repo.opener('bookmarks', 'w', atomictemp=True) for refspec, node in refs.iteritems(): file.write("%s %s\n" % (hex(node), encoding.fromlocal(refspec))) @@ -97,6 +109,10 @@ return if mark not in refs: mark = '' + if not valid(mark): + raise util.Abort(_("bookmark '%s' contains illegal " + "character" % mark)) + wlock = repo.wlock() try: file = repo.opener('bookmarks.current', 'w', atomictemp=True) diff -r 08f9c587141f -r 0fe36c347c00 tests/test-bookmarks.t --- a/tests/test-bookmarks.t Wed Feb 16 04:36:36 2011 +0100 +++ b/tests/test-bookmarks.t Wed Feb 16 18:36:45 2011 +0100 @@ -212,3 +212,10 @@ $ hg bookmark ' ' abort: bookmark names cannot consist entirely of whitespace [255] + +invalid bookmark + + $ hg bookmark 'foo:bar' + abort: bookmark 'foo:bar' contains illegal character + [255] +