We have moved to Github. Please open tickets there.

Opened 3 years ago

Closed 3 years ago

#1517 closed Defect (fixed)

XML-Output of REST API will be cutted if it has long content

Reported by: thomas Owned by:
Priority: high Milestone: Elgg 1.7
Component: Core Version: Github Master
Severity: minor Keywords:
Cc: brettp, cash Difficulty:

Description

Hi Cash,

I wanted to export an array with 20 elements with the XML REST API. So I wrote this code

function getusers($offset = 0, $limit = 20) {
		// Login to see private metadata
		my_login();
	
		$return = array();
		$users = elgg_get_entities(array('type' => "user", 'offset' => $offset, 'limit' => $limit)); 
		
		foreach($users as $user) {
			$user_array = array();
			$user_array['guid'] = $user->getGUID();
			$user_array['subtype'] = $user->getSubtype();
			$user_array['username'] = $user->username;
			$user_array['icon'] = $user->getIcon('small');
			$user_array['name'] = $user->name;
			$user_array['email'] = $user->email;
			$user_array['time_created'] = $user->time_created;
			$user_array['last_login'] = $user->last_login;
			$user_array['validated'] = $user->validated;
			$user_array['validated_email'] = $user->validated_email;
			array_push($return, $user_array);
		}
		
		// Logout
		my_logout();
		
		return $return;
	}

This works fine, if I have less than 10 users. If I set the limit to 10 or higher the output will be cutted at the end like this

<validated_email type="string"><![CDATA[svn:1]]></validated_

This always happens in the last line. When I export 100 elements. 99 are printed correctly an the last ist damaged.

Change History (10)

comment:1 Changed 3 years ago by cash

On a clean install, this works for me.

comment:2 Changed 3 years ago by thomas

I could solve this problem. In the view xml/pageshells/pageshell.php I have to comment out the

// header("Content-Length: " . strlen($vars['body']));

comment:3 Changed 3 years ago by cash

Thomas - I think this is a multi-byte character encoding issue. Will investigate.

comment:4 Changed 3 years ago by cash

Try replacing the strlen call with

mb_strlen($vars['body'], '8bit');

and let me know if that works.

comment:5 Changed 3 years ago by thomas

No, the output will be cutted at the same position.

comment:6 Changed 3 years ago by cash

Thomas, you said this happens with 10 or more users. This must mean there is data in the 10th user that is causing problems with the string length computation. Could you paste that data here so that I can try to reproduce it?

comment:7 Changed 3 years ago by thomas

first, sorry for my delayed reply.

I have to explain it a little more in detail: The fact with the 10 users was the first thing which showed me up the problem. In the meantime I noticed, that I'm also able to export for example 100 users. Then I will get 99 complete xml nodes and the last one is cutted off.

This does not happen, if the xml nodes only contain numbers. It seems that strlen count less chars if there are some utf8chars (like the name of the user) in the string.

Perhaps this is all an apache/php bug :(

I've to add, that I changed the following in the /lib/xml.php

$output .= '<![CDATA['.$value.']]>';

instead of converting it in htmlentities, because this made it impossible to watch the xml in a browser or parse it with simplexml.

comment:8 Changed 3 years ago by cash

(In [svn:3961]) Refs #1517: only encode <,>, and & for strings in xml

comment:9 Changed 3 years ago by cash

Thomas, what are your mbstring settings (from phpinfo())?

I'd also be interested in the simplest example where there is a cutoff in the xml data. I still haven't been able to reproduce this.

comment:10 Changed 3 years ago by cash

  • Resolution set to fixed
  • Status changed from new to closed

(In [svn:3963]) Fixes #1517 - let web server set content length on xml files

Note: See TracTickets for help on using tickets.