Re: QF hierselect: quotes and javascript?

From: Date: Wed, 26 Nov 2003 11:35:51 +0000
Subject: Re: QF hierselect: quotes and javascript?
References: 1 2  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-9154@lists.php.net to get a copy of this message
This won't do either. JS is not in the business of expanding entities (nor should it be!!). if you have a javascript like: media_categ_8[1] = new Array('29', 'O&quot;Reilly'); The content of the variable is treated literally as 'O&quot;Reilly' . The issue is that the same method input (array to populate the select) should be escaped in different ways: - html entities for creating <option> elements - quote escape for creating javascript variables The fix is very simple: line 155 of HTML/Quickform/hierselect.php: replace: $this->_js .= $varName."[".$i."] = new Array('".$value."', '".$text."');\n"; by: $this->_js .= $varName."[".$i."] = new Array('".$value."', '".addslashes( $text )."');\n"; I filed a bug upon Bertrand's suggestion. Cheers Ignatius _________________________ "Mike Carter" <mikeatwork@ukonline.co.uk> wrote in message news:11054A7BC9A71245BCBB991757932573100FE3@mail.koa.uk.com... > > > > -----Original Message----- > > From: Ignatius Reilly [mailto:ignatius.reilly@free.fr] > > > > I do not know whether this is a bug or a feature. > > > > Say I want to create a hierselect. One of the selects is > > passed a value pair > > ( "1" => "O'Reilly" ) > > The javascript will squeak because it fails to escape the quote: > > media_categ_8[1] = new Array('29', 'O'Reilly'); // produces a js > > error > > > > Of course I can not escape the string before passing the > > value to the select > > element the quote because the "O'Reilly" string will appear > > as the content > > node of an <option> tag: > > <option value="1">O\'Reilly</option> will not do. > > Not tested, just a quick idea, but... > you could convert your strings to HTML entities first? > > - Mike. > > > ________________________________________________________________________ > This email has been scanned for all viruses by the MessageLabs Email > Security System. For more information on a proactive email security > service working around the clock, around the globe, visit > http://www.messagelabs.com > ________________________________________________________________________

« previous php.pear.general (#9154) next »