sgzwiz / brython

Automatically exported from code.google.com/p/brython
BSD 3-Clause "New" or "Revised" License
0 stars 1 forks source link

.replace() can't really replace ? and $ #56

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
Try use .replace() to string which contains ? or $.

What is the expected output? What do you see instead?
Expected output:
>>> "$XE$".replace("$XE$", "!")
!
>>> "?XE".replace("?", "!")
'!XE'

and so on.

What do you see instead?
>>> "$XE$".replace("$XE$", "!") # replace doesn't work at all
$XE$
>>> "XE".replace("XE", "!") # this is OK
!
>>> "$XE".replace("$XE", "!") # but this is not
$XE
>>> "XE$".replace("XE$", "!")
XE$
>>> "XE$".replace("$", "!") # this is really weird
XE$!
>>> "$XE".replace("$", "!") # this even weirder
$XE!
>>> "?XE".replace("?", "!") # doesn't work at all
Exception!
>>> "XE?".replace("?", "!")
Exception!
>>> "XE!".replace("!", "?") # this works correctly
XE?

What version of the product are you using? On what operating system?
Version 1.0.20130126-094636

Original issue reported on code.google.com by bystrousak@kitakitsune.org on 27 Jan 2013 at 1:34

GoogleCodeExporter commented 9 years ago
Thanks, it's fixed in rev 471
Special characters [.*+?|()$^ were not escaped in the regular expression used 
in replace()

Original comment by pierre.q...@gmail.com on 2 Feb 2013 at 8:20