Ruby-specific CGI question (I think)

I’m using sessions and forms in my cgi script.

Unfortunately, for some reason, cgi.form seems to be putting some funny
stuff at the end of each form I make. (I have multiple forms on the
page, and it puts it on every one.) The funny stuff looks like this:

First of all: Why is it doing this?

Second of all: How do I make it stop?

-Kurt

Kurt M. Dresner graced us by uttering:

I’m using sessions and forms in my cgi script.

Unfortunately, for some reason, cgi.form seems to be putting
some funny stuff at the end of each form I make. (I have
multiple forms on the page, and it puts it on every one.) The
funny stuff looks like this:

First of all: Why is it doing this?

Session management. Session information has to be passed somehow
to mask the inherent statelessness of the CGI protocol.

Second of all: How do I make it stop?

Stop using cgi/session?

-Kurt

Tim Hammerquist

···


Familiarity breeds contempt – and children.
– Mark Twain

The problem is not that it is using session management. The problem is
that these things are being visually displayed in my web browser as
rectangles. Any idea how to make /that/ stop?

-Kurt

···

On Tue, Jul 15, 2003 at 09:53:39AM +0900, Tim Hammerquist wrote:

Kurt M. Dresner graced us by uttering:

I’m using sessions and forms in my cgi script.

Unfortunately, for some reason, cgi.form seems to be putting
some funny stuff at the end of each form I make. (I have
multiple forms on the page, and it puts it on every one.) The
funny stuff looks like this:

First of all: Why is it doing this?

Session management. Session information has to be passed somehow
to mask the inherent statelessness of the CGI protocol.

Second of all: How do I make it stop?

Stop using cgi/session?

-Kurt

Tim Hammerquist

Familiarity breeds contempt – and children.
– Mark Twain

======= End of Original Message =======<

Kurt M. Dresner graced us by uttering:

I’m using sessions and forms in my cgi script.

Unfortunately, for some reason, cgi.form seems to be putting
some funny stuff at the end of each form I make. (I have
multiple forms on the page, and it puts it on every one.) The
funny stuff looks like this:

First of all: Why is it doing this?

Session management. Session information has to be passed somehow
to mask the inherent statelessness of the CGI protocol.

Bless you, you have saved my sanity. I knew it had to be sending it
somehow, but couldn’t figure out why it wasn’t working and just realised I’m
not using cgi.rb to write the form (I’m using eruby instead).

Second of all: How do I make it stop?

My forms look like

  • that was generated by :

    <%= cgi.form(method=“get”) {
    cgi.text_field(“key”) +
    cgi.text_field(“value”) +
    cgi.submit(“add”)
    }
    %>

what does your ruby code look like ? Are you doing something funky?

···


Q: How many Zen masters does it take to screw in a light bulb?
A: None. The Universe spins the bulb, and the Zen master stays out
of the way.
Rasputin :: Jack of All Trades - Master of Nuns

Well… doesn’t fieldset draw a box?? I’ve never
used it, but I’ve seen documentation that says
it does that.

Why is ‘fieldset’ used there anyway? Will it work
if you remove it?

Hal

···

----- Original Message -----
From: “Kurt M. Dresner” kdresner@cs.utexas.edu
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Monday, July 14, 2003 8:36 PM
Subject: Re: ruby-specific CGI question (I think)

The problem is not that it is using session management. The problem is
that these things are being visually displayed in my web browser as
rectangles. Any idea how to make /that/ stop?


Hal Fulton
hal9000@hypermetrics.com

Yes, the fieldset is the problem, but I get the impression that Kurt
isn’t generating that himself, but rather that CGI::Session is
inserting it for him. It’d help if I could see the code, though.

-Mark

···

On Tue, Jul 15, 2003 at 10:45:52AM +0900, Hal E. Fulton wrote:

The problem is not that it is using session management. The problem is
that these things are being visually displayed in my web browser as
rectangles. Any idea how to make /that/ stop?

Well… doesn’t fieldset draw a box?? I’ve never
used it, but I’ve seen documentation that says
it does that.

Why is ‘fieldset’ used there anyway? Will it work
if you remove it?

The problem is not that it is using session management. The problem
is
that these things are being visually displayed in my web browser as
rectangles. Any idea how to make /that/ stop?

Well… doesn’t fieldset draw a box?? I’ve never
used it, but I’ve seen documentation that says
it does that.

Why is ‘fieldset’ used there anyway? Will it work
if you remove it?

Yes, the fieldset is the problem, but I get the impression that Kurt
isn’t generating that himself, but rather that CGI::Session is
inserting it for him. It’d help if I could see the code, though.

That’s my impression also; but why should the
session lib use that feature?

By ‘remove it’ I meant either save the HTML and
edit it out and see how it looks (may not be
possible) or simply (temporarily) change the
library source.

Hal

···

----- Original Message -----
From: “Mark J. Reed” markjreed@mail.com
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Monday, July 14, 2003 9:00 PM
Subject: Re: ruby-specific CGI question (I think)

On Tue, Jul 15, 2003 at 10:45:52AM +0900, Hal E. Fulton wrote:


Hal Fulton
hal9000@hypermetrics.com

Here’s my code folks. Again, I don’t profess to have anything that is
at all polished - I am just working something out:

-Kurt

#! /usr/bin/env ruby

require “cgi”
require “cgi/session”
require “setdeck”
require “set”
require “setcollection”
require “setboard”

cgi = CGI.new(“html4”)
addr = cgi.remote_addr.gsub(/./,‘d’)
sess = CGI::Session.new( cgi, “session_key” => “crappyset”,
“session_id” => addr,
“prefix” => “setgame.”,
“tmpdir” => “/tmp”)

if sess[“deck”].nil?
deck = SetDeck.new
sets = SetCollection.new
board = SetBoard.new(12)
deck.shuffle!
else
deck = Marshal.load(sess[“deck”])
sets = Marshal.load(sess[“sets”])
board = Marshal.load(sess[“board”])
end

if cgi.has_key?(‘selections’)
tomark = cgi[‘selections’][0].split(‘,’).collect { |x| x.to_i }
tomark.each do |marked|
if cgi.has_key?(‘uncheck’)
board.deselect(marked)
else
board.select(marked)
end
end
end

if cgi.has_key?(‘findset’)
board.markoneset
end

if cgi.has_key?(‘getset’)
newset = Set.new(board.removeSelected)
if newset.valid?
newset.collect
sets.add(newset)
else
takencards = newset.destroy
board.place(takencards) unless takencards.nil?
end
end

sess[“deck”] = Marshal.dump(deck)
sess[“sets”] = Marshal.dump(sets)
sess[“board”] = Marshal.dump(board)
sess.update

paramstring = “Session name: #{addr}” + cgi.br +
"Parameters: " +
(cgi.keys.collect { |key| key.to_s + ": " +
cgi[key].to_s}).join(cgi.br)

board.place(deck.dealn(board.holes.size))

cgi.out {
cgi.html {
cgi.head {“\n” + cgi.title {“What a crappy implementation of set!”}}

···
  • cgi.body {“\n” + cgi.pre{board.to_s} +
    cgi.br +
    cgi.form {
    cgi.textarea(“selections”) +
    cgi.br +
    cgi.submit(“Check Them”, “check”) +
    cgi.submit(“Un-Check Them”, “uncheck”)

                     } +
             cgi.form {cgi.submit("Collect Set", "getset")} +
             cgi.form {cgi.submit("Find Set", "findset")} \
    + paramstring
    

    }
    }
    }

On Tue, Jul 15, 2003 at 11:00:17AM +0900, Mark J. Reed wrote:

On Tue, Jul 15, 2003 at 10:45:52AM +0900, Hal E. Fulton wrote:

The problem is not that it is using session management. The problem is
that these things are being visually displayed in my web browser as
rectangles. Any idea how to make /that/ stop?

Well… doesn’t fieldset draw a box?? I’ve never
used it, but I’ve seen documentation that says
it does that.

Why is ‘fieldset’ used there anyway? Will it work
if you remove it?

Yes, the fieldset is the problem, but I get the impression that Kurt
isn’t generating that himself, but rather that CGI::Session is
inserting it for him. It’d help if I could see the code, though.

-Mark

======= End of Original Message =======<

From: “Mark J. Reed” markjreed@mail.com
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Monday, July 14, 2003 9:00 PM
Subject: Re: ruby-specific CGI question (I think)

The problem is not that it is using session management. The problem
is
that these things are being visually displayed in my web browser as
rectangles. Any idea how to make /that/ stop?

Well… doesn’t fieldset draw a box?? I’ve never
used it, but I’ve seen documentation that says
it does that.

Why is ‘fieldset’ used there anyway? Will it work
if you remove it?

Yes, the fieldset is the problem, but I get the impression that Kurt
isn’t generating that himself, but rather that CGI::Session is
inserting it for him. It’d help if I could see the code, though.

That’s my impression also; but why should the
session lib use that feature?

By ‘remove it’ I meant either save the HTML and
edit it out and see how it looks (may not be
possible) or simply (temporarily) change the
library source.

Even easier:

cgi.form() seems to just return a String - see that snippet I sent earlier:

formString = cgi.form(method=“get”) {
cgi.text_field(“key”) +
cgi.text_field(“value”) +
cgi.submit(“add”)
}

You should be able to work on formString like any other String,
remove any garbage that got in there, then just puts() it to the browser.

···

----- Original Message -----

On Tue, Jul 15, 2003 at 10:45:52AM +0900, Hal E. Fulton wrote:


Boston, n.:
Ludwig van Beethoven being jeered by 50,000 sports fans for
finishing second in the Irish jig competition.
Rasputin :: Jack of All Trades - Master of Nuns

Okay, here’s what’s going on. When you create a CGI::Session,
you pass it a CGI object. The session sets the @output_hidden instance
variable within the CGI query object to so that
elements get output at the end of every form.

Except that, for some strange reason known only to the author of cgi.rb,
it uses fieldsets:

  if @output_hidden
    hidden = @output_hidden.collect{|k,v|
      "<INPUT TYPE=HIDDEN NAME=\"#{k}\" VALUE=\"#{v}\">"
    }.to_s
    if defined? fieldset
      body += fieldset{ hidden }
    else
      body += hidden
    end
  end

The defined? test is just checking to see if fieldset is available -
which it is if you ask for html4, but not if you ask for html3.

I think this is clearly a bug in cgi.rb - there’s no reason to
put a fieldset around these elements just because you can. So
your options are:

  1. Modify your local copy of cgi.rb so that it doesn’t do that. :slight_smile:
    Great if you have permission to do that, otherwise no help.

  2. Ask for html3 instead of html4.
    This is a bad idea for other reasons, though. You don’t want to
    limit yourself to HTML 3, which is years out of date.

  3. Create your own modified version of cgi.form within the script that
    munges the result.

That last option goes something like this:

def fix_form(cgi, *args, &block)
    return cgi.form(*args, &block).gsub(/<\/?fieldset[^>]*/i, '')
end

Then everywhere you currently have

cgi.form { blah . . . }

Just replace it with

fix_form(cgi) { blah . . . }

-Mark

···

On Tue, Jul 15, 2003 at 11:10:55AM +0900, Kurt M. Dresner wrote:

cgi = CGI.new(“html4”)

By ‘remove it’ I meant either save the HTML and
edit it out and see how it looks (may not be
possible) or simply (temporarily) change the
library source.

Even easier:

cgi.form() seems to just return a String - see that snippet I sent
earlier:

formString = cgi.form(method=“get”) {
cgi.text_field(“key”) +
cgi.text_field(“value”) +
cgi.submit(“add”)
}

You should be able to work on formString like any other String,
remove any garbage that got in there, then just puts() it to the browser.

Oh, certainly. I’d have seen that if I had
a little less blood in my caffeine stream.

Hal

···

----- Original Message -----
From: “Rasputin” rasputin@idoru.mine.nu
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Monday, July 14, 2003 9:14 PM
Subject: Re: ruby-specific CGI question (I think)


Hal Fulton
hal9000@hypermetrics.com

Note, however, that this will remove all tags in the
form, so if you actually have legitimate uses for them, this isn’t
the way to go. You would need to make a smarter munger in that case.

-Mark

···

On Tue, Jul 15, 2003 at 11:43:28AM +0900, Mark J. Reed wrote:

def fix_form(cgi, *args, &block)
return cgi.form(args, &block).gsub(/</?fieldset[^>]/i, ‘’)
end

I think this is clearly a bug in cgi.rb - there’s no reason to
put a fieldset around these elements just because you can. So
your options are:

So now the question is, “How do we get this fixed in the real thing?”

-Kurt “doesn’t know about these kinds of things”

Typo correction:

def fix_form(cgi, *args, &block)
  return cgi.form(*args, &block).gsub(/<\/?fieldset[^>]*/i, '')
end

Left off the final >, which is no good. :slight_smile:

def fix_form(cgi, *args, &block)
    return cgi.form(*args, &block).gsub(/<\/?fieldset[^>]*>/i, '')
end

Note, however, that this will remove all tags in the
form, so if you actually have legitimate uses for them, this isn’t
the way to go. You would need to make a smarter munger in that case.

-Mark

···

On Mon, Jul 14, 2003 at 10:49:41PM -0400, Mark J. Reed wrote:

On Tue, Jul 15, 2003 at 11:43:28AM +0900, Mark J. Reed wrote:

···

----- Original Message -----
From: “Rasputin” rasputin@idoru.mine.nu
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Monday, July 14, 2003 9:14 PM
Subject: Re: ruby-specific CGI question (I think)

By ‘remove it’ I meant either save the HTML and
edit it out and see how it looks (may not be
possible) or simply (temporarily) change the
library source.

Even easier:

cgi.form() seems to just return a String - see that snippet I sent
earlier:

formString = cgi.form(method=“get”) {
cgi.text_field(“key”) +
cgi.text_field(“value”) +
cgi.submit(“add”)
}

You should be able to work on formString like any other String,
remove any garbage that got in there, then just puts() it to the browser.

Oh, certainly. I’d have seen that if I had
a little less blood in my caffeine stream.

:slight_smile:

I’d never have seen it in a million years if cgi/session.rb didn’t
have lots of head-shaped dents in it after me spending all night
trying to get sessions in .rhtml files working…


How much does it cost to entice a dope-smoking UNIX system guru to Dayton?
– Brian Boyle, UNIX/WORLD’s First Annual Salary Survey
Rasputin :: Jack of All Trades - Master of Nuns