Aspyct.org

Ruby bit me for the first time

| Comments

As you may know, I’m currently building a man to html converter in ruby. I noticed that in many manpages, we have < signs, that must, of course, be escaped in html. After a bit of looking around, I added a few lines of code to fix that issue. Quick fix, easy win :) Then things went weird!

Have a look at the screenshot below, especially the highlighted zones. See? Despite calling the exact same script with the exact same arguments, output is different from one shell to another: &lt; vs <.

I quickly suspected the shell below to use an old version of the script, despite the fact that the which points to the right file. So I modified something in the file, and saw the change happen in both shells. But the &lt; was still there…

After a while, I realized that rvm might be playing a trick on me. And indeed! The shell above uses ruby 1.8.7, where the shell below uses 1.9.3. And apparently, these two versions of ruby handle characters differently…

1
2
3
4
5
rednose:~ aspyct$ ruby --version
ruby 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin12.0]
rednose:~ aspyct$ irb
>> ?<
=> 60
1
2
3
4
5
rednose:~ aspyct$ ruby --version
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin12.0.0]
rednose:~ aspyct$ irb
1.9.3-p194 :001 > ?<
 => "<"

Good to know, let’s solve this bug now :)

Comments