From: Aristarkh A Zagorodnikov Date: 2001-07-14T23:28:02+09:00 Subject: [ruby-talk:17842] Bug ... probably another one Hello! Consider the following example: def expand_path(path, _path_info = '') doc_path = 'documents' path = File.expand_path doc_path + path pwd = Dir.pwd << '/' << doc_path document = path.dup path.slice! 0, pwd.length puts document if File.exist? document puts _path_info.inspect puts((_path_info.scan /.{8}$/).inspect) else path = path.split '/' _path_info.insert 0, ('/' << path.pop) expand_path((path.join '/'), _path_info) end end expand_path '/index.html/' << ARGV[0].to_s This is a ripped-down version of function which is intended to locate the real document and it's path info from the uri: i.e if given uri is "/index.html/test", and /index.html is a plain file, then uri stripped to "/index.html" and path_info is "test". The algorithm itself is simple (recursing, cutting one path-delimited element at once until document with such name is found). This function does not perform the task (real one has support for directories and directory index dociments), but I just stripped it down to demonstrate: Make 'documents' directory, and place 'index.html' file inside it, then put above example in the directory where 'documents' reside in. Go to that dir and just run it, supplying optional path_info argument. The bug does not show first - the path_info string is obviously correct, but when I try to get last 8 characters it gets crazy. empty path_info - right (empty path_info, no match): xm@ns:~/ruby/test$ ruby tb.rb /home/xm/ruby/test/documents/index.html "" [] short path_info - right (normal path_info, no match): xm@ns:~/ruby/test$ ruby tb.rb 123456 /home/xm/ruby/test/documents/index.html/123456 /home/xm/ruby/test/documents/index.html "/123456" [] 8-char path_info - right (normal path_info, normal match): xm@ns:~/ruby/test$ ruby tb.rb 12345678 /home/xm/ruby/test/documents/index.html/12345678 /home/xm/ruby/test/documents/index.html "/12345678" ["12345678"] 9-char path_info - right (normal path_info, normal match): xm@ns:~/ruby/test$ ruby tb.rb 1234567890 /home/xm/ruby/test/documents/index.html/1234567890 /home/xm/ruby/test/documents/index.html "/1234567890" ["34567890"] a bit longer path_info - WRONG (normal path_info, match contains something which looks like garbage): xm@ns:~/ruby/test$ ruby tb.rb 12345678901 /home/xm/ruby/test/documents/index.html/12345678901 /home/xm/ruby/test/documents/index.html "/12345678901" ["\320<\"@\020\000\000\000"] even longer path_info - WRONG (normal path_info, match contains something which looks like garbage):xm@ns:~/ruby/test$ ruby tb.rb 12345678901324324 /home/xm/ruby/test/documents/index.html/12345678901324324 /home/xm/ruby/test/documents/index.html "/12345678901324324" ["\000\000)\000\000\000\a\000"] What the hell is going on here? Maybe regexps don't work in this case for some reason? What's that garbage then? Aristarkh A Zagorodnikov, Lead Programmer, W3D Group http://www.w3d.ru /// xm@w3d.ru /// ICQ UIN 36987938