Re: backslashes get stripped from $ signs

will kahn-greene <[email protected]> Sat, 08 Jan 2011 17:26:43 -0500
Newsgroups gmane.comp.web.pyblosxom.user
Message-ID <[email protected]>
On 01/08/2011 04:56 PM, Dieter Plaetinck wrote:
> On Mon, 27 Dec 2010 11:46:48 +0100
> Dieter Plaetinck <dieter-7FYLOmueu/[email protected]> wrote:
>> +        var_dict['body'] = var_dict['body'].replace(r'\$', '\\\$')
>>      replacer = Replacer(request, encoding, var_dict)
>>      return _VAR_REGEXP.sub(replacer.replace, template)
>>  
>>
>> this kind of works, except that for some reason i need 3 backslashes
>> in the replacement, and this will also change '$' into '\$', which i
>> don't want, obviously. changing the first param to '\\$' doesn't help
>> either.  I'm not sure what the 'r' is for, but I saw it in
>> BlosxomRenderer:render_template(), and using it doesn't seem to
>> change anything.
> 
> anyone an idea?  on a python commandline shell I can just do:
> str.replace('\$', '\\$') 
> but I have no idea why I can't get it to work in Pyblosxom/tools.py

The line you're doing on the python repl is different than the one
you're doing in your patch.  The r in r'...' is for raw.  It means that
the enclosed string won't have escape sequences interpreted.  See:

http://docs.python.org/reference/lexical_analysis.html#string-literals

That's from the 2.7 docs, but it's been true in Python for a long time.

/will

------------------------------------------------------------------------------
Gaining the trust of online customers is vital for the success of any company
that requires sensitive data to be transmitted over the Web.   Learn how to 
best implement a security strategy that keeps consumers' information secure 
and instills the confidence they need to proceed with transactions.
http://p.sf.net/sfu/oracle-sfdevnl