Bug in regex engine ?? Must be...

D

D. Krmpotic

Hi,

I'm using Ruby 1.8.6, and I just discovered something rather
interesting, here is a test:

require 'test/unit'

class TestRegexBug < Test::Unit::TestCase

def test_bug

hours = "pon-Äet"

assert(hours =~ /[Ä]et/i)
assert(hours =~ /Äet/i)
assert(hours =~ /-Äet/i)
assert(hours =~ /[cÄ]et/i)
assert(hours =~ /-[Ä]et/i)

end

end

As you can see, this only happens with unicode letters... (the last test
fails).. I'm used to the fact that //i doesn't work for unicode chars
and I already know that you need two dots to match one of these.. But
this problem is different and weirder, because what triggers it is a
minus sign before the square brackets.. if you remove either the '-' or
'[]' from the regex, it works..

Can you comment?

thank you,
david
 
R

Rob Biedenharn

Hi,

I'm using Ruby 1.8.6, and I just discovered something rather
interesting, here is a test:

$KCODE =3D 'UTF8'
require 'jcode'
require 'test/unit'

class TestRegexBug < Test::Unit::TestCase

def test_bug

hours =3D "pon-=C4=8Det"

assert(hours =3D~ /[=C4=8D]et/i)
assert(hours =3D~ /=C4=8Det/i)
assert(hours =3D~ /-=C4=8Det/i)
assert(hours =3D~ /[c=C4=8D]et/i)
assert(hours =3D~ /-[=C4=8D]et/i)

end

end

As you can see, this only happens with unicode letters... (the last =20=
test
fails).. I'm used to the fact that //i doesn't work for unicode chars
and I already know that you need two dots to match one of these.. But
this problem is different and weirder, because what triggers it is a
minus sign before the square brackets.. if you remove either the '-' =20=
or
'[]' from the regex, it works..

Can you comment?

thank you,
david


Ruby is not natively aware of unicode, but you can get all these to =20
pass if you give it the $KCOCDE hint.

-Rob

Rob Biedenharn http://agileconsultingllc.com
(e-mail address removed)
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top