tags:

views:

39

answers:

2

Hi, I write a little ruby script, which sends me an email when a new commit added to our svn.

I get the log with this code:

log = `/usr/bin/svnlook log #{ARGV[0]}`

When I run my script from bash I get good encoded character in the email, but when I try it and create a new commit I get wrong hungarian characters.

I commited this:
tes őéá

I get this in the email:
Log: tes ?\197?\145?\195?\169?\195?\161

How can I solve this issue?

A: 

By default, Ruby doesn't support Unicode, which is the encoding of those Hungarian characters. Unless you can commit using only ASCII, you'll need to look into using a Unicode library of some sort, e.g. ruby-unicode.

In my experience, Python has much better Unicode support than Ruby, so if your script isn't doing much more than that, I'd consider Python or another scripting language.

EDIT: Apparently while I wasn't looking, Ruby 1.9 went and added proper(ish) Unicode support. I haven't tried it myself, but this blog post goes through a couple of exercises that I think detail all the necessary functions (which isn't many).

bnaul
A: 

Yes, Ruby is in the process of supporting Unicode (differently). The libraries are in flux, catching up with Ruby 1.9.

To track down your bug, you need to figure out what is different between your two cases. Maybe when your commit hook gets run, it has a different path, and therefore different Ruby? Is it the same machine? Is it the same email client? It could be at several different levels all the way from the interpreter that reads the email template to different clients reading the email. You have any more info?

ndp
Yes, it's on the same server. When I execute for test this is what I call: ./post-commit /repository/ and this is what the svn server call when a commit finished. My post-commit bash script contains: REPOS="$1"REV="$2"ruby /repository/hooks/mail.rb "$REPOS" "$REV"I don't know wat can be the problem. I tried it with p UniversalDetector::chardet(message). It tell me that when I call the script the encoding is utf-8, when the commit calls it's an ASCII code.
Roland Soós
You could try sending $LOAD_PATH, $_, $0, $*, $". There must be something different in the environment.
ndp