Skip to content

Commit

Permalink
Merge pull request #31 from ignacioalles/utf8
Browse files Browse the repository at this point in the history
Fix UTF8 handling
  • Loading branch information
miqwit committed Jun 4, 2024
2 parents 76e150b + 1fe7671 commit c8c184f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
13 changes: 6 additions & 7 deletions src/Controller/ErnParserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -431,11 +431,9 @@ private function listPossibleFunctionNames($prefix, $tag) {
* 'MESSAGERECIPIENT', 'PARTYID'], then will call
* $this->ern->getMESSAGEHEADER()->getMESSAGERECIPIENT()->setPARTYID($value)
*
* @param type $value Value to set
* @param string $value Value to set
*/
private function setCurrentElement($value) {
$this->log($value . ": " . implode("->", array_keys($this->pile)));

// Use last element in pile
$keys = array_keys($this->pile);

Expand All @@ -452,11 +450,13 @@ private function setCurrentElement($value) {
if (!empty($this->lastElement) && $this->lastElement[0] === $elem && $this->lastElement[1] === $tag) {
$value = $this->lastElement[2] . $value;
}
$value_clean = trim($value);
$this->log($value_clean . ": " . implode("->", array_keys($this->pile)));
[$func_name, $elem] = $this->getValidFunctionName("set", $tag, $elem);

// It's possible we're trying to set a text but it's expecting an
// object (where text should be placed in value).
$value_inst = $this->instanciateTypeFromDoc($elem, $func_name, $value);
$value_inst = $this->instanciateTypeFromDoc($elem, $func_name, $value_clean);

$this->lastElement = [$elem, $tag, $value];

Expand Down Expand Up @@ -603,13 +603,12 @@ private function instanciateTypeFromDoc($class, $function, $value_default) {
* @param string $data
*/
private function callbackCharacterData($parser, string $data) {
$data_clean = trim($data);
if ($data_clean === "") {
if (trim($data) === "") {
// do nothing
return;
}

$this->setCurrentElement($data_clean);
$this->setCurrentElement($data);
}

/**
Expand Down
1 change: 1 addition & 0 deletions tests/Controller/ParserControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ public function testSample016Utf8Artist() {
/* @var $srdbt_zero SoundRecordingDetailsByTerritoryType */
$srdbt_zero = $resource_zero->getSoundRecordingDetailsByTerritory()[0];
$this->assertEquals("Mirko Kordić", $srdbt_zero->getDisplayArtist()[0]->getPartyName()[0]->getFullName());
$this->assertEquals("N. Áutor", $srdbt_zero->getResourceContributor()[1]->getPartyName()[0]->getFullName());

// Check that Reference Title of Sound Recording 3 (idx 2) is Zvečansko kolo
/* @var $resource_two \DedexBundle\Entity\Ern382\SoundRecordingType */
Expand Down
2 changes: 1 addition & 1 deletion tests/samples/016_utf8_artists.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
</ResourceContributor>
<ResourceContributor>
<PartyName>
<FullName>N.Autor</FullName>
<FullName>N. Áutor</FullName>
</PartyName>
<ResourceContributorRole>Producer</ResourceContributorRole>
</ResourceContributor>
Expand Down

0 comments on commit c8c184f

Please sign in to comment.