can't modify literal regexp: why?

Discussion in 'Ruby' started by Jeremy Stephens, Nov 13, 2007.

  1. I was just curious as to why this is illegal.

    Example:
    $ irb
    >> /blah/.clone

    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?
    --
    Posted via http://www.ruby-forum.com/.
     
    Jeremy Stephens, Nov 13, 2007
    #1
    1. Advertising

  2. Jeremy Stephens

    7stud -- Guest

    Jeremy Stephens wrote:
    > I was just curious as to why this is illegal.
    >
    > Example:
    > $ irb
    >>> /blah/.clone

    > 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

    --
    Posted via http://www.ruby-forum.com/.
     
    7stud --, Nov 13, 2007
    #2
    1. Advertising

  3. 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
    > >> /blah/.clone

    > 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.

    --
    Nobu Nakada
     
    Nobuyoshi Nakada, Nov 14, 2007
    #3
  4. Nobuyoshi Nakada wrote:
    > 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.
    --
    Posted via http://www.ruby-forum.com/.
     
    Jeremy Stephens, Nov 14, 2007
    #4
  5. Jeremy Stephens

    Eric Hodel Guest

    On Nov 14, 2007, at 06:48 , Jeremy Stephens wrote:
    > Nobuyoshi Nakada wrote:
    >> 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/

    --
    Poor workers blame their tools. Good workers build better tools. The
    best workers get their tools to do the work for them. -- Syndicate Wars
     
    Eric Hodel, Nov 14, 2007
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mr. SweatyFinger

    why why why why why

    Mr. SweatyFinger, Nov 28, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    991
    Mark Rae
    Dec 21, 2006
  2. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,260
    Smokey Grindel
    Dec 2, 2006
  3. Replies:
    13
    Views:
    555
    Dave Thompson
    Nov 15, 2004
  4. Anonieko Ramos

    What's wrong with rpc-literal? Why use doc-literal?

    Anonieko Ramos, Sep 27, 2004, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    413
    Anonieko Ramos
    Sep 27, 2004
  5. Joao Silva
    Replies:
    16
    Views:
    408
    7stud --
    Aug 21, 2009
Loading...

Share This Page