[PATCH] Obfuscate Me Gently

Brendan Cully brendan at kublai.com
Wed Jul 5 22:09:39 UTC 2006


Any comment on either of the two alternatives (escaping only 7-bit
characters, which is enough to obfuscate email addresses, or
attempting to convert to unicode before obfuscating and falling back
to obfuscating byte by byte)?

The current form encourages latin-1 over utf-8 for pretty changelogs
:)

On Friday, 30 June 2006 at 11:47, Brendan Cully wrote:
> On Friday, 30 June 2006 at 11:32, Eric Hopper wrote:
> > On Fri, Jun 30, 2006 at 11:15:41AM -0700, Brendan Cully wrote:
> > > Any further thoughts on this? I'm not actually sure how to properly
> > > encode utf-8 as &#..; entities, and I do think this approach will
> > > provide complete coverage for e-mail addresses, since they don't
> > > contain 8-bit characters anyway.
> > 
> > utf-8 and &# are different ways to do the same thing.  Both are about
> > how to encode characters from the full Unicode character set using a
> > more limited set of characters.
> 
> Yeah, I just didn't know how to get UCS out of those strings (I don't
> do a lot of unicode). But the following patch seems to work.

> # HG changeset patch
> # User Brendan Cully <brendan at kublai.com>
> # Node ID 86f71b55bc28d11d84ea8181b6e10641d6d45511
> # Parent  b73552a00b209c8fcd71fd23fb990c5d05910010
> Attempt to convert strings from UTF-8 before obfuscating them.
> This should avoid accidentally splitting UTF-8 characters.
> 
> diff -r b73552a00b20 -r 86f71b55bc28 mercurial/templater.py
> +++ b/mercurial/templater.py	Fri Jun 30 11:46:03 2006 -0700
> @@ -230,6 +230,10 @@ def nl2br(text):
>      return text.replace('\n', '<br/>\n')
>  
>  def obfuscate(text):
> +    try:
> +        text = unicode(text, 'utf-8')
> +    except UnicodeDecodeError:
> +        pass
>      return ''.join(['&#%d;' % ord(c) for c in text])
>  
>  def domain(author):

> _______________________________________________
> Mercurial mailing list
> Mercurial at selenic.com
> http://selenic.com/mailman/listinfo/mercurial




More information about the Mercurial mailing list