cgi - cleaning tabs and returns out of textarea

Glenn Stauffer java at dejazzd.com
Mon Jan 28 09:17:41 EST 2002


I have a cgi utility which I wrote to process form data and save key-value
pairs in a database.  Since it is a generic utility, I need to handle any
type of data and store it in a form that can be converted into a
tab-delimited download.

In many browsers, tabs and carriage returns can be embedded in a textarea
field.

I wrote this function to strip these characters:

def clean(text, tab_width):
	text = text.strip() + ' '
	return text.expandtabs(tab_width)

The problem I've run into is that the return/linefeed characters are embedded
within the value returned from the form and strip() won't work.  I wrote
another function that tests each character and strips the carriage
return/linefeeds, but I'm finding that  browsers often replace a return with
a carriage return/linefeed and I end up with two spaces in the text.

I'm working on figuring out the best way to do this, but thought I'd send to
the list to see if someone could steer me in the right direction.

Thanks,

Glenn

-------------------------------------------------------




More information about the Python-list mailing list