error installing RDoc documentation: incompatible encoding regexp match
michael.rp almost had it, but no quotes on the environment string for Windows. The same solution for Linux appears in the link supplied by jerry. For Windows:
set RDOCOPT=--encoding=UTF-8
I put this in the RubyInstaller\Ruby1.9.3\setup_environment.bat
file so it is always there.
Ruby: incompatible encoding regexp match
Just encode the regex in UTF-8:
str = 'é'
arr = str.split(/x/mu)
#=> ["é"]
Documentation: https://ruby-doc.org/core-2.3.1/Regexp.html#class-Regexp-label-Encoding Regex Error - (incompatible encoding regexp match (UTF-8 regexp with ASCII-8BIT string)
The Net::HTTP
standard library only returns binary (ASCII-8BIT
) strings. See the long-standing feature request: Feature #2567: Net::HTTP does not handle encoding correctly. So if you want UTF-8 strings you have to manually set their encoding to UTF-8 with String#force_encoding
:
source_code.force_encoding(Encoding::UTF_8)
If the website's character encoding isn't UTF-8 you have to implement a heuristic based on the Content-Type
header or <meta>
's charset
attribute but even then it might not be the correct encoding. You can validate a string's encoding with String#valid_encoding?
if you need to deal with such cases. Thankfully most websites use UTF-8 nowadays.Also as @WiktorStribiżew already wrote in the comments, the regexp encoding specifiers s
(Windows-31J) and u
(UTF-8) modifiers aren't necessary here and only very rarely are. Especially the latter one since modern Ruby defaults to UTF-8 (or, if sufficient, its subset US-ASCII) anyway. In other programming languages they may have a different meaning, e.g. in Perl s
means single line.
Pushing rdoc documentation to rubygems.org
When you upload your gem into rubygems.org, it automatically uploads the documentation in rubydoc.info
The guide to upload the gem: http://guides.rubygems.org/publishing/
hope it helps
encoding and utf-8 exceptions after upgrade to Ruby 1.9.3 and rails 3.2
I had the same problem occuring "sometimes", I use now at the very top of each .rb
files the following:
# encoding: UTF-8
class Whatever < ActiveRecord::Base
...
end
The problem occurs when the file contains one/several accent(s) (as a french guy, I sometimes use it in comments). jekyll regeneration failed with unicode posts
chcp 65001
in cmd helps me everytime before running jekyll. But I think it is not full solution
Related Topics
Why Should @@Class_Variables Be Avoided in Ruby
Use Pry in Gems Without Modifying The Gemfile or Using 'Require'
Rails 3, Http Extensions (Webdav) and Rack App Mounting
Why Does Array.To_S Return Brackets
Ruby 2.0 Bytecode Export/Import
Stripping Commas from Integers or Decimals in Rails
Axlsx - Formatting Text Within a Cell
How to Avoid Circular Creation of Associated Models in Factory_Girl
How to Tell a Ruby Method to Expect a Specific Parameter Type
Get Value from String Representing Local Variable
More Ruby Way of Doing Project Euler #2
Include Module in All Minitest Tests Like in Rspec