[typo] Ruby 1.9 questions

Edward Middleton emiddleton at bebear.net
Mon Oct 5 10:42:44 EDT 2009


Perry Smith wrote:
> Second, am I the first explore of these here Typo, Ruby 1.9
> netherlands?  Anyone wanna combine efforts?

I have pretty much finished porting to 1.9.1 but to get things working I
needed to patch soap4r[1] actionwebservice[2] the mysql-ruby[3] driver,
and actionpack to get things working.  It also seems to be using about
70M as appose to 50M on 1.8.  A lot of things aren't handling 1.9 string
encodings properly and most of the proposed patches are nasty hack that
just override the results rather then fixing the cause of the problem.

Edward

1. http://github.com/emiddleton/soap4r
2. http://github.com/emiddleton/actionwebservice
3. http://github.com/emiddleton/mysql-ruby

--- ./actionpack-2.3.4.orig/lib/action_view/template_handlers/erb.rb
2009-09-04 23:09:20.043938934 +0900
+++ ./actionpack-2.3.4/lib/action_view/template_handlers/erb.rb
2009-10-05 00:28:13.000000000 +0900
@@ -15,8 +15,24 @@

         # Ruby 1.9 prepends an encoding to the source. However this is
         # useless because you can only set an encoding on the first line
-        RUBY_VERSION >= '1.9' ? src.sub(/\A#coding:.*\n/, '') : src
+        if RUBY_VERSION >= '1.9'
+          enc = detect_magic_comment(template.source) ||
Encoding.find('UTF-8')
+          src.force_encoding(enc).sub(/\A#coding:.*\n/, '')
+        else
+          src
+        end
       end
+      private
+        def detect_magic_comment(s)
+          if /\A<%#(.*)%>/ =~ s or (@percent and /\A%#(.*)/ =~ s)
+            comment = $1
+            comment = $1 if comment[/-\*-\s*(.*?)\s*-*-$/]
+            if %r"coding\s*[=:]\s*([[:alnum:]\-_]+)" =~ comment
+              enc = $1.sub(/-(?:mac|dos|unix)/i, '')
+              enc = Encoding.find(enc)
+            end
+          end
+        end
     end
   end
 end


More information about the Typo-list mailing list