Ruby 1.9.1 Regexp Encoding Warnings

M

Mikel Lindsaar

In the Mail gem I am doing Regexp's on various strings that arrive,
which can be basically anything (user defined). So I am dup'ing the
string, and forcing the encoding to binary before I do the regexp...
but I am getting this warning:

~/lib/mail/utilities.rb:56: warning: regexp match /.../n against to UTF-8 string

The code that produces that is:

aspecial = %Q|()<>[]:;.\\,"|
control = %Q|\x00-\x1f\x7f-\xff|
PHRASE_UNSAFE = /[#{Regexp.quote aspecial}#{control}]/n

def quote_phrase( str )
if RUBY_VERSION >= '1.9'
string = str.dup
string.force_encoding('ASCII-8BIT')
(PHRASE_UNSAFE === string) ? dquote(str) : str
else
(PHRASE_UNSAFE === str) ? dquote(str) : str
end
end

Any clues?

The specs that generate these errors all pass, so the Regexp is doing
what I intend it to do from what I can see.
 
M

Mikel Lindsaar

In the Mail gem I am doing Regexp's on various strings that arrive,
which can be basically anything (user defined). So I am dup'ing the
string, and forcing the encoding to binary before I do the regexp...
but I am getting this warning:

~/lib/mail/utilities.rb:56: warning: regexp match /.../n against to UTF-8 string

Found the problem. Was a second regexp inside the first that was not
properly encoded.

Mikel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,152
Members
46,697
Latest member
AugustNabo

Latest Threads

Top