php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #38657 WDDX does not work anymore
Submitted: 2006-08-30 12:32 UTC Modified: 2006-08-30 14:00 UTC
From: tom at ideaweb dot de Assigned:
Status: Closed Package: WDDX related
PHP Version: 4.4.4 OS: Debian, OSX
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: tom at ideaweb dot de
New email:
PHP Version: OS:

 

 [2006-08-30 12:32 UTC] tom at ideaweb dot de
Description:
------------
I have a small cms which works over year, but with the upgrade from php-4.4.2 on Debian Sarge to php-4.4.4 wddx does not work anymore. I go back to the old version and it works. I used the same configuration script for both php versions.

The problem is, its not easy for me as an admin to find the right portion of code, but tried to reproduce this on my mac, not linux, because its a production machine. i got malformed wddx output with my show() method. on my linux machine the wddx output was empty.

i hope it helps and i made no mistakes :)

Reproduce code:
---------------
<?php
	function ideacms_isutf8( $pString, $pComp = false ) {/*{{{*/

		if( !$pComp ) {
			return preg_match( '%^(?:
				[\x09\x0A\x0D\x20-\x7E]             # ASCII
				| [\xC2-\xDF][\x80-\xBF]            # non-overlong 2-byte
				|  \xE0[\xA0-\xBF][\x80-\xBF]       # excluding overlongs
				| [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte
				|  \xED[\x80-\x9F][\x80-\xBF]       # excluding surrogates
				|  \xF0[\x90-\xBF][\x80-\xBF]{2}    # planes 1-3
				| [\xF1-\xF3][\x80-\xBF]{3}         # planes 4-15
				|  \xF4[\x80-\x8F][\x80-\xBF]{2}    # plane 16
				)*$%xs', $pString
			);
		}

		//if( utf8_encode( utf8_decode( $pString ) ) == $pString ) {
		if( iconv( 'ISO-8859-1', 'UTF-8', iconv( 'UTF-8', 'ISO-8859-1', $pString ) ) == $pString ) {
			return true;
		}
		return false;
	}/*}}}*/

	Class CMS_WDDX
	{
		var $name;
		var $packet;
	
		function CMS_WDDX( $pName ) {/*{{{*/
	
			$this->name = $pName;
			$this->packet = wddx_packet_start( $pName );
		}/*}}}*/
	
		function setVar( $pName, $pValue, $pOrd = false ) {/*{{{*/
		
			eval( "\$$pName = \$this->entities(\$pValue, \$pOrd);" );
			
			wddx_add_vars( $this->packet, $pName );
			
		}/*}}}*/
		
		function show() {/*{{{*/
		
			//var_dump( wddx_packet_end( $this->packet ) );exit;

			if( !$this->packet ) return false;
	
			return wddx_packet_end( $this->packet );
		}/*}}}*/
	
		function entities( $pString, $pOrd = false ) {/*{{{*/
	
			if ( is_array( $pString ) ) {
				foreach( $pString as $key => $value ) {
					$pString[$key] = CMS_WDDX::entities( $pString[$key], $pOrd );
				}
			}
			elseif ( is_string( $pString ) ) {
				
				if( strpos( phpversion(), '4' ) === 0 ) {
				
					if ( $pOrd === true ) {
						
						if ( ideacms_isutf8( $pString ) ) {
							if( $pTemp = @utf8_decode( $pString ) ) {
								$pString = $pTemp;
							}
						}
					
						$pString = CMS_WDDX::unentities( $pString );
					
						$temp = htmlspecialchars( $pString, ENT_NOQUOTES );
		
						$pString = '';
			
						for( $i = 0; $i < strlen( $temp ); $i++ ) {
			
							$ord = ord($temp{$i});
			
							if($ord >= 126){
								$pString .= "&#".$ord.";";
							}
							else {
								switch($ord){
									case 34 :
										$pString .= '"';
										break;
									case 39 : 
										$pString .= "'";
										break;
									case 92 : 
										$pString .= "\\";
										break;
									default : 
										$pString .= $temp{$i};
								}
							}
						}
					}
				}
				else {
					
					$pString = CMS_WDDX::convert( $pString );
				
					//$pString = CMS_WDDX::unentities( $pString );
					
					//$pString = htmlspecialchars( $pString, ENT_NOQUOTES );
				}
			}
			return $pString;
	
		}/*}}}*/
	
		function unentities( $pString ) {/*{{{*/
	
			if ( is_array( $pString ) ) {
				foreach( $pString as $key => $value ) {
					$pString[$key] = CMS_WDDX::unentities( $pString[$key] );
				}
			}
			elseif ( is_string( $pString ) ) {
				
				$pString = ideacms_unentities( $pString, ( isset( $GLOBALS['ideacms_template_init'] ) ? false : true ) );
			}
			return $pString;
	
		}/*}}}*/
		
		function convert( $pString ) {/*{{{*/
		
			#return $pString;
			
			if ( is_array( $pString ) ) {
				foreach( $pString as $key => $value ) {
					$pString[$key] = CMS_WDDX::convert( $pString[$key] );
				}
			}
			elseif ( is_string( $pString ) ) {
			
				if( !ideacms_isutf8( $pString ) ) {
					if( $pTemp = @utf8_encode( $pString ) ) {
						$pString = $pTemp;
					}
				}
			}
			
			return $pString;
			
		}/*}}}*/
		
		function unconvert( $pString ) {/*{{{*/
		
			return $pString; 
			
		}/*}}}*/
	
	}
	$w = new CMS_WDDX( 'test' );
	$w->setVar( "test", "1234567890123456" );

	echo "<pre>";
	echo ( $w->show() );
	echo "</pre>";
?>

Expected result:
----------------
<pre><wddxPacket version='1.0'><header><comment>test</comment></header><data><struct><var name='test'><string>1234567890123456</string></var></struct></data></wddxPacket></pre>

Actual result:
--------------
<pre><wddxPacket version='1.0'><header><comment>test</comment></header><data><struct><va<string>1234567890123456</string></var></struct></data></wddxPacket></pre>

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-08-30 13:53 UTC] werner at esmt dot org
i did and it works for my test case on my mac and it seems there are no problems with my linux server too :)

but the behaviour of ex. german 'umlaute' changed from

<var name="DATA_bbbbbbb">
 <string>bbbb&#228;bbBBB</string>
</var>

to

<var name="DATA_bbbbbbb">
 <string>bbbb<char code="E4" />bbBBB</string>
</var>

but its my problem...

did you know when i can expect the next php4 version? i feel not safe with a snapshot on my production machine...

thx a lot, thomas
 [2006-08-30 14:00 UTC] tony2001@php.net
Fixed -> closed.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 06:01:29 2024 UTC