This post originated from an RSS feed registered with Ruby Buzz
by Eric Stewart.
Original Post: Getting RuBlog Working
Feed Title: Ponderings On Ruby
Feed URL: http://blog.eric-stewart.com/category/programming-ruby.rss
Feed Description: This is the Ruby related section of Eric Stewart's weblog. These entries will be the commentary of a long time Java/C++ programmer that started exploring Ruby in 2003.
When I recently decided to give RuBlog a shot, I needed to install Ruby on
my web server. I rushed out and downloaded Ruby 1.8.0 and installed it
without a hitch, installed RDoc, and then attempted to get RuBlog up and
running.
With a few minor changes to a custom rublog.cgi script, my new empty blog
came up like a charm. I added a simple rdoc entry, and then a plain text
entry, and they worked great!
But when I attempted to click on a specific Link, or a category, or the
Syndicate link, up came the apache error message. A review of the logs
pointed out that I Can’t modify frozen string. Ok, fine. A
quick check of the code turned up this problem code:
# Work out the request path, and make it local to out datadir. Ignore it
# if it contains any '..' sequences
def determine_request_path
request_path = ""
path = @environment['PATH_INFO']
if path && path !~ /\.\./
path.slice!(0) if path[0] == ?/
request_path = path unless path.empty?
end
@is_rss = request_path.sub!(/index.rss$/, '') || @parameters.has_key?('rss')
@path = request_path
end
The error occurred when the code attempted to slice the path, since it was
apparently frozen when fetched from the environment. The problem was fixed
by changing the if block to:
if path && path !~ /\.\./
mutable_path = path.dup
mutable_path.slice!(0) if mutable_path[0] == ?/
request_path = mutable_path unless mutable_path.empty?
end
For complete Ruby newbies like myself, the dup operation was
necessary because it creates a new object with the same data, not state. If
I had used path.clone instead of path.dup the frozen
state would have been carried over.
Since Ruby 1.8.0 was released in August and the last RuBlog release
3f8
came
out in March, I am not too shocked by all this.
Update: It turns out, the latest cvs versions of everything in the
RubLog distribution work just fine with Ruby 1.8.0, so problem was already
solved. It gave me a chance to hack a little ruby though!