[#3907] Obtaining mode information on an IO object — Jos Backus <jos@...>

The attached patch implements IO#mode. This method returns the mode the IO

17 messages 2004/12/06
[#3909] Re: [patch] Obtaining mode information on an IO object — nobu.nokada@... 2004/12/07

Hi,

[#3910] Re: [patch] Obtaining mode information on an IO object — Jos Backus <jos@...> 2004/12/07

On Tue, Dec 07, 2004 at 09:25:13AM +0900, nobu.nokada@softhome.net wrote:

[#3925] Re: [patch] Obtaining mode information on an IO object — James Britt <ruby@...> 2004/12/09

Jos Backus wrote:

[#4009] cgi.rb -- more GET/POST stuff — mde@...26.com

First of all, I think it would be great, as Eustaquio suggests, to

17 messages 2004/12/23
[#4016] Re: [PATCH] cgi.rb -- more GET/POST stuff — Francis Hwang <sera@...> 2004/12/24

GETs and POSTs are defined to be fairly different actions. I'd read

[#4027] Allowing custom number literal suffixes? — Florian Gro<florgro@...>

Moin!

35 messages 2004/12/27
[#4070] Re: Allowing custom number literal suffixes? — nobu.nokada@... 2005/01/02

Hi,

[#4072] Re: Allowing custom number literal suffixes? — Mathieu Bouchard <matju@...> 2005/01/02

[#4079] Re: Allowing custom number literal suffixes? — Florian Gro<florgro@...> 2005/01/03

Mathieu Bouchard wrote:

[#4081] Re: Allowing custom number literal suffixes? — Mathieu Bouchard <matju@...> 2005/01/03

[#4082] Re: Allowing custom number literal suffixes? — Florian Gro<florgro@...> 2005/01/03

Mathieu Bouchard wrote:

[#4084] Re: Allowing custom number literal suffixes? — Brent Roman <brent@...> 2005/01/04

I'm not sure I would advocate making Ruby's grammar even more

[#4086] Re: Allowing custom number literal suffixes? — Mathieu Bouchard <matju@...> 2005/01/04

[#4033] Garbage collection trouble — Christian Neukirchen <chneukirchen@...>

Hello,

13 messages 2004/12/27

cgi.rb GET and POST values patch

From: "Eustaquio Rangel de Oliveira Jr." <eustaquiorangel@...>
Date: 2004-12-22 20:37:38 UTC
List: ruby-core #4006
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello there.  :-)

First of all, let me say that I'm just learning Ruby and think that is
really a wonderful language and have a very fine community. People are cool
here. :-)

I'm just reading and learning how to program in Ruby for some few days, and
as I use PHP as my main web development language, I'm testing mod_ruby and
eruby.

One thing I missed is a way to put the GET and POST values on differente
places there. I think it's more safe to keep it separated, there is a good
discussion about this here:

http://simon.incutio.com/archive/2003/10/25/difference

I use to always refer to my posted form values in different way I get the
parameters that came from the URL. Don't know what you guys think about it,
but I think is a good way to *try* to avoid some "dirty tricks" that people
can do. Let me hear what you think about that. :-)

But, I just took my chances here and developed (!) a patch (!!) for the
cgi.rb module, that allow to reference to the POST and GET parameters
values on different places. There was

CGI.params

and it is still there, no need to changes, but there is now

CGI.get_params

and

CGI.post_params

and I made this based on the env_method value.

Making a little test here with a eruby file, I attached the file
eruby_form.rhtml.
Tell me what you think about.

I'm attaching also the patch file, I really don't know if I did that the
right way, forgive me some mistakes but I'm still (and will keep) learning
about Ruby.

Thanks for your attention and keep the good work! :-)

- ----------------------------
Eust痃uio "TaQ" Rangel
eustaquiorangel@yahoo.com
http://beam.to/taq
Usu疵io GNU/Linux no. 224050
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFBydlBb6UiZnhJiLsRAmZ2AKCl5f8K7+skL2hmxR77AEzr8FGjuACdGMtj
NyUvEofUqvktFCxWrac5JMU=
=ODr9
-----END PGP SIGNATURE-----

--------------050808070301030607000002
Content-Type: text/plain;
 name="eruby_form.rhtml"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="eruby_form.rhtml"

<% 
	require 'cgi' # Require the CGI library
	cgi       = CGI.new()  # New CGI object
	username  = cgi.post_params['username']		# post username
	get_test  = cgi.get_params['get_test_param'] # get test param 
%>
<html><head><title>eRuby Test</title></head>
  <body>
    <h1>Testing eRuby</h1>
    <% if username.empty? # Print out the form asking for the username %>
      <form method="post">
        Please enter your username: <input type="text" name="username"><br>
        <input type="submit" value="Go">
		</form>
		<% if !get_test.empty? %>
			You told me that the get test parameter is <%= get_test %>
		<% end %>
    <% else %>
      Welcome <%= username %>!
	<% end %>
  </body>
</html>

--------------050808070301030607000002
Content-Type: text/plain;
 name="cgi.rb.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="cgi.rb.patch"

--- cgi.rb.old	2004-12-22 13:30:36.000000000 -0200
+++ cgi.rb	2004-12-22 14:54:13.000000000 -0200
@@ -891,7 +891,7 @@
   #     #  "name2" => ["value1", "value2", ...], ... }
   #
   def CGI::parse(query)
-    params = Hash.new([].freeze)
+    params      = Hash.new([].freeze)
 
     query.split(/[&;]/n).each do |pairs|
       key, value = pairs.split('=',2).collect{|v| CGI::unescape(v) }
@@ -956,6 +956,8 @@
     # Get the parameters as a hash of name=>values pairs, where
     # values is an Array.
     attr("params")
+    attr("get_params")
+    attr("post_params")
 
     # Set all the parameters.
     def params=(hash)
@@ -963,6 +965,16 @@
       @params.update(hash)
     end
 
+    def get_params=(hash)
+      @get_params.clear
+      @get_params.update(hash)
+    end
+
+    def post_params=(hash)
+      @post_params.clear
+      @post_params.update(hash)
+    end
+
     def read_multipart(boundary, content_length)
       params = Hash.new([])
       boundary = "--" + boundary
@@ -1117,6 +1129,9 @@
                   )
       end
 
+      @get_params  = env_table['REQUEST_METHOD'] == "GET"  ? @params : Hash.new([])
+      @post_params = env_table['REQUEST_METHOD'] == "POST" ? @params : Hash.new([])
+
       @cookies = CGI::Cookie::parse((env_table['HTTP_COOKIE'] or env_table['COOKIE']))
     end
     private :initialize_query
@@ -2265,11 +2280,15 @@
       initialize_query()  # set @params, @cookies
     else
       if defined?(CGI_PARAMS)
-        @params  = CGI_PARAMS.nil?  ? nil : CGI_PARAMS.dup
-        @cookies = CGI_COOKIES.nil? ? nil : CGI_COOKIES.dup
+        @params      = CGI_PARAMS.nil?  ? nil : CGI_PARAMS.dup
+        @cookies     = CGI_COOKIES.nil? ? nil : CGI_COOKIES.dup
+        @get_params  = CGI_PARAMS.nil? ?  nil : (env_table['REQUEST_METHOD'] == "GET"  ? CGI_PARAMS.dup : nil)
+        @post_params = CGI_PARAMS.nil? ?  nil : (env_table['REQUEST_METHOD'] == "POST" ? CGI_PARAMS.dup : nil)
       else
         initialize_query()  # set @params, @cookies
-        params  = @params.nil?  ? nil : @params.dup
+        params      = @params.nil?  ? nil : @params.dup
+        get_params  = env_table['REQUEST_METHOD'] == "GET"  ? params.dup : nil
+        post_params = env_table['REQUEST_METHOD'] == "POST" ? params.dup : nil
         cookies = @cookies.nil? ? nil : @cookies.dup
         (class << self; self; end).class_eval do
           const_set(:CGI_PARAMS,  params)

--------------050808070301030607000002--

In This Thread

Prev Next