Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

BUGFIX: Looping over a PaginatedList in the template caused a seg fau…

…lt/bus error.
  • Loading branch information...
commit ab34688273fd74109fd229d758f0b502e1230f54 1 parent 1e6a526
@simonwelsh simonwelsh authored
Showing with 14 additions and 8 deletions.
  1. +6 −0 tests/view/SSViewerTest.php
  2. +8 −8 view/SSViewer.php
View
6 tests/view/SSViewerTest.php
@@ -967,6 +967,12 @@ function testRenderWithSourceFileComments() {
SSViewer::set_source_file_comments(false);
}
+ function testLoopIteratorIterator() {
+ $list = new PaginatedList(new ArrayList());
+ $viewer = new SSViewer_FromString('<% loop List %>$ID - $FirstName<br /><% end_loop %>');
+ $result = $viewer->process(new ArrayData(array('List' => $list)));
+ $this->assertEquals($result, '');
+ }
}
/**
View
16 view/SSViewer.php
@@ -23,7 +23,7 @@
class SSViewer_Scope {
// The stack of previous "global" items
- // And array of item, itemIterator, pop_index, up_index, current_index
+ // And array of item, itemIterator, itemIteratorTotal, pop_index, up_index, current_index
private $itemStack = array();
protected $item; // The current "global" item (the one any lookup starts from)
@@ -40,7 +40,7 @@ class SSViewer_Scope {
function __construct($item){
$this->item = $item;
$this->localIndex=0;
- $this->itemStack[] = array($this->item, null, null, null, 0);
+ $this->itemStack[] = array($this->item, null, 0, null, null, 0);
}
function getItem(){
@@ -48,9 +48,8 @@ function getItem(){
}
function resetLocalScope(){
- list($this->item, $this->itemIterator, $this->popIndex, $this->upIndex, $this->currentIndex) = $this->itemStack[$this->localIndex];
+ list($this->item, $this->itemIterator, $this->itemIteratorTotal, $this->popIndex, $this->upIndex, $this->currentIndex) = $this->itemStack[$this->localIndex];
array_splice($this->itemStack, $this->localIndex+1);
- $this->itemIteratorTotal = $this->itemIterator ? $this->itemIterator->count() : 0;
}
function obj($name){
@@ -59,11 +58,11 @@ function obj($name){
case 'Up':
if ($this->upIndex === null) user_error('Up called when we\'re already at the top of the scope', E_USER_ERROR);
- list($this->item, $this->itemIterator, $unused2, $this->upIndex, $this->currentIndex) = $this->itemStack[$this->upIndex];
+ list($this->item, $this->itemIterator, $this->itemIteratorTotal, $unused2, $this->upIndex, $this->currentIndex) = $this->itemStack[$this->upIndex];
break;
case 'Top':
- list($this->item, $this->itemIterator, $unused2, $this->upIndex, $this->currentIndex) = $this->itemStack[0];
+ list($this->item, $this->itemIterator, $this->itemIteratorTotal, $unused2, $this->upIndex, $this->currentIndex) = $this->itemStack[0];
break;
default:
@@ -78,14 +77,14 @@ function obj($name){
break;
}
- $this->itemStack[] = array($this->item, $this->itemIterator, null, $this->upIndex, $this->currentIndex);
+ $this->itemStack[] = array($this->item, $this->itemIterator, $this->itemIteratorTotal, null, $this->upIndex, $this->currentIndex);
return $this;
}
function pushScope(){
$newLocalIndex = count($this->itemStack)-1;
- $this->popIndex = $this->itemStack[$newLocalIndex][2] = $this->localIndex;
+ $this->popIndex = $this->itemStack[$newLocalIndex][3] = $this->localIndex;
$this->localIndex = $newLocalIndex;
// We normally keep any previous itemIterator around, so local $Up calls reference the right element. But
@@ -111,6 +110,7 @@ function next(){
$this->itemStack[$this->localIndex][1] = $this->itemIterator;
$this->itemIteratorTotal = iterator_count($this->itemIterator); //count the total number of items
+ $this->itemStack[$this->localIndex][2] = $this->itemIteratorTotal;
$this->itemIterator->rewind();
}
else {
Please sign in to comment.
Something went wrong with that request. Please try again.