[#6660] Ruby on Neko ? — Nicolas Cannasse <ncannasse@...>

Hi folks,

14 messages 2005/11/19

[#6672] testing for hardlink with "test(?-, ...)" flawed on Windows — noreply@...

Bugs item #2858, was opened at 2005-11-20 16:35

13 messages 2005/11/20

[#6684] semenatics of if/unless/while statement modifiers — Stefan Kaes <skaes@...>

Hi all,

81 messages 2005/11/21
[#6685] Re: semenatics of if/unless/while statement modifiers — Mauricio Fern疣dez <mfp@...> 2005/11/22

On Tue, Nov 22, 2005 at 08:22:59AM +0900, Stefan Kaes wrote:

[#6686] Re: semenatics of if/unless/while statement modifiers — Stefan Kaes <skaes@...> 2005/11/22

Mauricio Fern疣dez wrote:

[#6687] Re: semenatics of if/unless/while statement modifiers — Eric Hodel <drbrain@...7.net> 2005/11/22

On Nov 21, 2005, at 4:37 PM, Stefan Kaes wrote:

[#6689] Re: semenatics of if/unless/while statement modifiers — Stefan Kaes <skaes@...> 2005/11/22

Eric Hodel wrote:

[#6693] Re: semenatics of if/unless/while statement modifiers — Yukihiro Matsumoto <matz@...> 2005/11/22

Hi,

[#6695] Re: semenatics of if/unless/while statement modifiers — Stefan Kaes <skaes@...> 2005/11/22

Yukihiro Matsumoto wrote:

[#6718] Re: semenatics of if/unless/while statement modifiers — mathew <meta@...> 2005/11/22

[#6722] Re: semenatics of if/unless/while statement modifiers — Stefan Kaes <skaes@...> 2005/11/22

mathew wrote:

[#6707] Re: semenatics of if/unless/while statement modifiers — "David A. Black" <dblack@...> 2005/11/22

Hi --

[#6708] Re: semenatics of if/unless/while statement modifiers — Stefan Kaes <skaes@...> 2005/11/22

David A. Black wrote:

[#6714] Re: semenatics of if/unless/while statement modifiers — "David A. Black" <dblack@...> 2005/11/22

Hi --

[#6717] Re: semenatics of if/unless/while statement modifiers — Stefan Kaes <skaes@...> 2005/11/22

David A. Black wrote:

[#6798] ruby 1.8.4 preview2 — Yukihiro Matsumoto <matz@...>

Hi,

37 messages 2005/11/30

[Patch] lib/shellwords.rb

From: Kev Jackson <kevin.jackson@...>
Date: 2005-11-07 07:20:47 UTC
List: ruby-core #6581
Ok, here's my first patch (so be kind ;)

I was looking for files to document as part of the ongoing ruby doc 
effort and I came across some code which I thought could do with 
refactoring - shellwords.rb

I've attached the patch and associated testcases (Test::Unit)

Hope everything is in order

Kev

Attachments (2)

shellwords.rb.patch (1.39 KB, text/x-diff)
Index: lib/shellwords.rb
===================================================================
RCS file: /src/ruby/lib/shellwords.rb,v
retrieving revision 1.8
diff -u -r1.8 shellwords.rb
--- lib/shellwords.rb	10 Nov 2004 07:16:24 -0000	1.8
+++ lib/shellwords.rb	4 Nov 2005 10:23:40 -0000
@@ -33,23 +33,16 @@
     until line.empty?
       field = ''
       loop do
-	if line.sub!(/\A"(([^"\\]|\\.)*)"/, '') then
-	  snippet = $1.gsub(/\\(.)/, '\1')
-	elsif line =~ /\A"/ then
-	  raise ArgumentError, "Unmatched double quote: #{line}"
-	elsif line.sub!(/\A'([^']*)'/, '') then
-	  snippet = $1
-	elsif line =~ /\A'/ then
-	  raise ArgumentError, "Unmatched single quote: #{line}"
-	elsif line.sub!(/\A\\(.)?/, '') then
-	  snippet = $1 || '\\'
-	elsif line.sub!(/\A([^\s\\'"]+)/, '') then
-	  snippet = $1
-	else
-	  line.lstrip!
-	  break
-	end
-	field.concat(snippet)
+        case line
+        when line.sub!(/\A"(([^"\\]|\\.)*)"/, ''): snippet = $1.gsub(/\\(.)/,'\1')
+        when line =~ /\A"/: raise ArgumentError, "Unmatched double quote: #{line}"
+        when line =~ /\A'/: raise ArgumentError, "Unmatched single quote: #{line}"
+        when line.sub!(/\A\\(.)?/, ''): snippet = $1 || '\\'
+        when line.sub!(/\A([^\s\\'"]+)/, '') or line.sub!(/\A'([^']*)'/, ''): snippet = $1
+        else line.lstrip! 
+        break
+        end
+	      field.concat(snippet)
       end
       words.push(field)
     end
test_shellwords.rb (847 Bytes, text/x-ruby)
require 'test/unit'
require 'shellwords'

class TestShellwords < Test::Unit::TestCase

  include Shellwords

  def setup
    @not_string = Class.new
    @cmd = "ruby my_prog.rb | less"
  end


  def test_not_string  
      assert_raises ArgumentError do 
        shellwords(@not_string)
    end
  end
  
  def test_string
    assert_instance_of(Array, shellwords(@cmd))
    assert_equal(4, shellwords(@cmd).length)
  end
  
  def test_unmatched_double_quote
    bad_cmd = 'one two "three'
    assert_raises ArgumentError do
      shellwords(bad_cmd)
    end
  end
  
  def test_unmatched_single_quote
    bad_cmd = "one two 'three"
    assert_raises ArgumentError do
      shellwords(bad_cmd)
    end
  end
  
  def test_unmatched_quotes
    bad_cmd = "one '"'"''""'""
    assert_raises ArgumentError do
      shellwords(bad_cmd)
    end
  end
end

In This Thread

Prev Next