can't modify literal regexp: why?

J

Jeremy Stephens

I was just curious as to why this is illegal.

Example:
$ irbSecurityError: can't modify literal regexp
from (irb):1:in `initialize_copy'
from (irb):1:in `clone'
from (irb):1
Regexp.new(/blah/).clone is perfectly OK. What's insecure about cloning
a literal regex?
 
7

7stud --

Jeremy said:
I was just curious as to why this is illegal.

Example:
$ irb
SecurityError: can't modify literal regexp
from (irb):1:in `initialize_copy'
from (irb):1:in `clone'
from (irb):1

Regexp.new(/blah/).clone is perfectly OK. What's insecure about cloning
a literal regex?


(/blah/).clone
 
N

Nobuyoshi Nakada

Hi,

At Wed, 14 Nov 2007 05:56:12 +0900,
Jeremy Stephens wrote in [ruby-talk:278872]:
I was just curious as to why this is illegal.

Example:
$ irb
SecurityError: can't modify literal regexp
from (irb):1:in `initialize_copy'
from (irb):1:in `clone'
from (irb):1

Regexp.new(/blah/).clone is perfectly OK. What's insecure about cloning
a literal regex?

It is to prohibit /blah/.initialize_copy(/foobar/). You may
know, /blah/.dup works.
 
J

Jeremy Stephens

Nobuyoshi said:
Hi,

At Wed, 14 Nov 2007 05:56:12 +0900,
Jeremy Stephens wrote in [ruby-talk:278872]:
Regexp.new(/blah/).clone is perfectly OK. What's insecure about cloning
a literal regex?

It is to prohibit /blah/.initialize_copy(/foobar/). You may
know, /blah/.dup works.

Thanks for the info. Anyone know _why_ it's prohibited? Just curious.
 
E

Eric Hodel

Nobuyoshi said:
Hi,

At Wed, 14 Nov 2007 05:56:12 +0900,
Jeremy Stephens wrote in [ruby-talk:278872]:
Regexp.new(/blah/).clone is perfectly OK. What's insecure about
cloning
a literal regex?

It is to prohibit /blah/.initialize_copy(/foobar/). You may
know, /blah/.dup works.

Thanks for the info. Anyone know _why_ it's prohibited? Just
curious.

x = /x/.dup
x.send :initialize_copy, /y/
p x # => /y/
 

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,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top