Sublime Forum

Ruby encoding build bug

#1

Hi. I’ve tried to meake simple ruby script and here a problem.

require 'open-uri'
url = '/Users/<user>/Documents/123.html'
page = open(url)
text = page.read

fields = text.scan(/field"><a href="\/\w*"/)
puts "Fields = #{fields}"

here’s the script.
If i’ve run it in terminal — it works fine.
If i’ve run it in sublime 3 build — it get’s this error: “:7:in `scan’: invalid byte sequence in US-ASCII (ArgumentError)”
This error resolves by including this line in the beginning of the file: Encoding.default_external = Encoding::UTF_8
After that it builds fine by sublime.

i can’t add screenshots due to forum crash.

I’ve trying to automate this thing by add an argument “-E:UTF-8” to sublime ruby.sublime-build
This fix error with encoding but gets native ruby but with .read method: `read’: “\xD0” on US-ASCII (Encoding::InvalidByteSequenceError)
So this bug fixing by add to /etc/environment:
this line: “LC_TYPE=en_US.UTF-8”
and then create:
$ sudo locale-gen en_US.UTF-8
and here’s i’m stuck

So there is two question:

  1. Why i should write exact encoding in sublime while default ruby compiler works well with default file.
  2. How can i add external encoding to sublime build system without that bug.

I’m using OSX 10.10 Dev 6 preview
Sublime 3 3059
ruby 2.0.0p481 (2014-05-08 revision 45883) [universal.x86_64-darwin14]

0 Likes