PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » HTML » Pager » Bug #6812

htmlentities in _generateFormOnClickHelper($data, $prev = '') mangles utf8 valu

Details

Submitted2006-02-17 14:42 UTC
Fromjoeofclew at yahoo dot com
Assignedquipo
StatusClosed
PackagePager
PHP Version5.1.2
OSfedora 4
Roadmaps(Not assigned)

Comments

[2006-02-17 14:42 UTC] joeofclew at yahoo dot com

Description:
------------
htmlentities in _generateFormOnClickHelper($data, $prev = '') mangles utf8 value
this breaks my form when the pager links are clicked, as it creaets a garbage value for the form element with the utf8 encoded value

Test script:
---------------
안녕
(note: hello in korean)

Expected result:
----------------
%26%23xC548%3B%26%23xB155%3B

Actual result:
--------------
ë'&xxx;&yyy

[2006-02-17 14:44 UTC] kmh496 at kornet dot net

fix for me is changing name of form element for the js case, and using urlencode
i don't know if this will break code which depends on htmlentities, however

// $escapedData = htmlentities($escapedData, ENT_QUOTES);
if ($prev=='search') {
$prev = 'urlencoded_search';
$escapedData = urlencode($escapedData);
}

[2006-02-17 19:25 UTC] kmh496 at kornet dot net

i tried a direct reply, was bounced.
i don't have a test case.
it's jut another hidden var
<input value=hidden name=search value='UTF8HERE'>
then debug the posted vars.
Alberton 쓰시길:
> Hi,
>
> > Package: Pager
> > Bug Type: Bug
> > Bug description: htmlentities in
_generateFormOnClickHelper($data, $prev = '') mangles utf8 valu
> >
> > Description:
> > ------------
> > htmlentities in _generateFormOnClickHelper($data, $prev =
'') mangles utf8
> > value
> > this breaks my form when the pager links are clicked, as it
creaets a
> > garbage value for the form element with the utf8 encoded
value
>
> Can you send me a full reproducing script?

it's a little hard to generate a test case.
i just have <input type=hidden name=search value='속'>
which is a hidden value with a utf8 value for it.
i think you can more easily add it to an existing case which you
have
hanging around.

for a euc-kr value -- also multibyte -- just pull something off
www.naver.com

> Does it work fine if you replace
> $escapedData = htmlentities($escapedData, ENT_QUOTES);
> with
> $escapedData = htmlentities(urlencode($escapedData),
ENT_QUOTES);
>
> in _generateFormOnClickHelper() ?
>

the problem is that for that special value which has to be
urlencoded,
i have to also urldecode php-wise. if i use your suggestion, i
would
have to urldecode all the values because i can't tell which one
was
changed in the process. you know what i mean? it comes out the
other
end as %ab%4a%3b like that .. following the suggestion. i also
need to
change its name to know which to urldecode.

another option is to use javascript to escape it. the escapes
might get
stripped off when php handles POST vars in normal processing,
but i
don't know that.

the following may help with javascript ideas. put your
multibyte in
there and see what javascript transforms it to.

http://jesus2099.free.fr/blog/2005/07/test-en-ligne-dencodages-en-php-et.html

> Thanks for your help
>
if you wonder what all this is for.....

my site is www.myowndictionary.com

the problem is with entering a search term.

thx.

[2006-02-19 06:26 UTC] kmh496 at kornet dot net

how about this.
i will try this.
<?php htmlentities($text, ENT_QUOTES, 'UTF-8') ?>

[2006-03-09 00:53 UTC] kmh496 at kornet dot net

the following works great. thank you.
(the system killed my previous prompt -- and verbose -- reply)

$escapedData = str_replace($search, $replace, $data);
// am I forgetting any dangerous whitespace?
// would a regex be faster?
// if it's already encoded, don't encode it again
// if (!$this->_isEncoded($escapedData)) {
// $escapedData = urlencode($escapedData);
//}
$escapedData = htmlentities($escapedData, ENT_QUOTES, 'UTF-8');

[2006-04-03 13:07 UTC] kmh496 at kornet dot net

hello again.
if i do that, however,
<quote from above>
the problem is that for that special value which has to be urlencoded,i have to also urldecode php-wise. if i use your suggestion, i would have to urldecode all the values because i can't tell which one was changed in the process.
</end quote from above>

the UTF-8 parameter works for me. I haven't tested it with other charsets, you may need to revisit then, but my problem was solved thanks, already.

[2006-04-03 13:41 UTC] kmh496 at kornet dot net

i must take back my last comment. I don't remember why i said that i had to uncomment the section which did the 'urlencode' function to get it to work the first time (:

my setup is:

//'mode' => 'Sliding', //try switching modes
'mode' => 'Jumping',

and i am using

$selectBoxO = $pager->getPerPageSelectBox();

with
// if (!$this->_isEncoded($escapedData)) {
// $escapedData = urlencode($escapedData);
// }
(a commented out section) i get

input.value = "<a href="#" >부가물</a>";

as the output of _generateFormOnClickHelper

but with (If i don't uncomment the section)
if (!$this->_isEncoded($escapedData)) {
$escapedData = urlencode($escapedData);
}
i get

input.type = "hidden"; input.name = "word"; input.value = "%3Ca+href%3D%22%23%22+%3E%EC%A7%95%EC%97%AD%3C%2Fa%3E";

and only then does it work properly.

[2006-04-23 09:12 UTC] joeofclew at yahoo dot com

this is kmh496 at kornet.net

the new function does work as it is in cvs, along with the new common.php, HtmlWidgets.php, Jumping.php

thank you.