Skip to content

Commit b88e09a

Browse files
committed
filter fields by index was wrong for wildcards
1 parent ab200a9 commit b88e09a

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/File_MARC_Reference.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,20 @@ private function referenceFields()
418418

419419
/* filter on indizes */
420420
if ($_indexRange = $this->getIndexRange($this->spec['field'], count($this->fields))) {
421-
$this->fields = array_intersect_key($this->fields, array_flip($_indexRange));
421+
$prevTag = "";
422+
$index = 0;
423+
foreach($this->fields as $position => $field) {
424+
if(false == ($field instanceof File_MARC_Field)) {
425+
continue;
426+
}
427+
$tag = $field->getTag();
428+
$index = ($prevTag == $tag or "" == $prevTag) ? $index : 0;
429+
if(!in_array($index, $_indexRange)) {
430+
unset($this->fields[$position]);
431+
}
432+
$index++;
433+
$prevTag = $tag;
434+
}
422435
}
423436

424437
/* filter on indicators */

test/ReferenceTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ public function testGetRepeatable()
7979
$this->assertTrue(17 == $Reference->data[0]->getPosition());
8080
$this->assertTrue(18 == $Reference->data[1]->getPosition());
8181
}
82+
83+
public function testGetRepeatableWildcard()
84+
{
85+
$Reference = new File_MARC_Reference('0..[1]', $this->record);
86+
$this->assertSame(1, count($Reference->data));
87+
}
8288

8389
public function testGetRepeatableWildCardSubstring()
8490
{

0 commit comments

Comments
 (0)