Skip to content

Commit

Permalink
Fixed encoding error of &nsbp;
Browse files Browse the repository at this point in the history
  • Loading branch information
magicsunday committed Dec 13, 2021
1 parent aa0fcdd commit e6d4d61
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/Traits/IndividualTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,14 @@ private function getIndividualData(Individual $individual, int $generation): arr

// The name of the person without formatting of the individual parts of the name.
// Remove placeholders as we do not need them in this module
$fullNN = str_replace(['@N.N.', '@P.N.'], '', $primaryName['fullNN']);
$fullNN = str_replace(
[
Individual::NOMEN_NESCIO,
Individual::PRAENOMEN_NESCIO,
],
'',
$primaryName['fullNN']
);

// Extract name parts (Do not change processing order!)
$preferredName = $this->getPreferredName($xpath);
Expand All @@ -101,8 +108,8 @@ private function getIndividualData(Individual $individual, int $generation): arr
'isAltRtl' => $this->isRtl($alternativeNames),
'thumbnail' => $this->getIndividualImage($individual),
'sex' => $individual->sex(),
'birth' => $this->decodeValue(strip_tags($individual->getBirthDate()->display())),
'death' => $this->decodeValue(strip_tags($individual->getDeathDate()->display())),
'birth' => $this->decodeValue($individual->getBirthDate()->display()),
'death' => $this->decodeValue($individual->getDeathDate()->display()),
'timespan' => $this->getLifetimeDescription($individual),
'color' => $this->getColor($individual),
'colors' => [[], []],
Expand Down Expand Up @@ -161,7 +168,9 @@ private function getLifetimeDescription(Individual $individual): string
*/
private function getBirthYear(Individual $individual): string
{
return $individual->getBirthDate()->minimumDate()->format('%Y');
return $this->decodeValue(
$individual->getBirthDate()->minimumDate()->format('%Y')
);
}

/**
Expand All @@ -173,19 +182,21 @@ private function getBirthYear(Individual $individual): string
*/
private function getDeathYear(Individual $individual): string
{
return $individual->getDeathDate()->minimumDate()->format('%Y');
return $this->decodeValue(
$individual->getDeathDate()->minimumDate()->format('%Y')
);
}

/**
* Convert HTML entities to their corresponding characters.
* Removes HTML tags and converts/decodes HTML entities to their corresponding characters.
*
* @param string $value
*
* @return string
*/
private function decodeValue(string $value): string
{
return strip_tags($value);
return html_entity_decode(strip_tags($value), ENT_QUOTES, 'UTF-8');
}

/**
Expand Down

0 comments on commit e6d4d61

Please sign in to comment.