~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/commit.py

  • Committer: John Arbash Meinel
  • Date: 2005-09-18 16:09:41 UTC
  • mto: (1185.1.32)
  • mto: This revision was merged to the branch mainline in revision 1390.
  • Revision ID: john@arbash-meinel.com-20050918160940-ab133a1f31616576
Added test cases for handling bogus files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
57
57
        If null (default), a time/random revision id is generated.
58
58
    """
59
59
 
60
 
    import time, tempfile
 
60
    import time, tempfile, re
61
61
 
62
62
    from bzrlib.osutils import local_time_offset, username
63
63
    from bzrlib.branch import gen_file_id
144
144
            timezone = local_time_offset()
145
145
 
146
146
        mutter("building commit log message")
 
147
        # Python strings can include characters that can't be
 
148
        # represented in well-formed XML; escape characters that
 
149
        # aren't listed in the XML specification
 
150
        # (http://www.w3.org/TR/REC-xml/#NT-Char).
 
151
        if isinstance(message, unicode):
 
152
            char_pattern = u'[^\x09\x0A\x0D\u0020-\uD7FF\uE000-\uFFFD]'
 
153
        else:
 
154
            # Use a regular 'str' as pattern to avoid having re.subn
 
155
            # return 'unicode' results.
 
156
            char_pattern = '[^x09\x0A\x0D\x20-\xFF]'
 
157
        message, escape_count = re.subn(
 
158
            char_pattern,
 
159
            lambda match: match.group(0).encode('unicode_escape'),
 
160
            message)
 
161
        if escape_count:
 
162
            note("replaced %d control characters in message", escape_count)
147
163
        rev = Revision(timestamp=timestamp,
148
164
                       timezone=timezone,
149
165
                       committer=committer,