A&B
is stored in vb_user as A&B
and the importer just puts the very same pre-encoded value into xf_user.utf8_unhtml
) is only called for invalidly encoded strings (because of the added !preg_match('/./u', $value)
). So validly encoded strings aren't HTML-decoded anymore.$post['pagetext'] = $this->_convertToUtf8($post['pagetext']);
'username' => $this->_convertToUtf8($post['username'], true),
public function set($field, $value, array $options = [])
{
$options = array_replace([
'convertUtf8' => true,
'forceConstraint' => true,
'unHtml' => false
], $options);
Index: src/XF/Import/Data/EntityEmulator.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/XF/Import/Data/EntityEmulator.php (revision 2751d0d4532870fd9dd4b0483268ec991c93e5e0)
+++ src/XF/Import/Data/EntityEmulator.php (date 1521212333000)
@@ -27,6 +27,21 @@
protected $oldId = null;
+ /**
+ * Convert text to UTF8 on set()
+ */
+ const CONVERT_UTF8 = 'convertUtf8';
+
+ /**
+ * Force type constraints on set()
+ */
+ const FORCE_CONSTRAINT = 'forceConstraint';
+
+ /**
+ * Convert HTML entities to raw values on set()
+ */
+ const UNHTML_ENTITIES = 'unHtmlEntities';
+
public function __construct(
AbstractData $handler, \XF\Mvc\Entity\Structure $structure, \XF\Mvc\Entity\ValueFormatter $valueFormatter
)
@@ -50,8 +65,9 @@
public function set($field, $value, array $options = [])
{
$options = array_replace([
- 'convertUtf8' => true,
- 'forceConstraint' => true
+ self::CONVERT_UTF8 => true,
+ self::FORCE_CONSTRAINT => true,
+ self::UNHTML_ENTITIES => false
], $options);
$columns = $this->structure->columns;
@@ -83,11 +99,11 @@
$vf = $this->valueFormatter;
$originalValue = $value;
- if ($options['convertUtf8'])
+ if ($options[self::CONVERT_UTF8])
{
if ((is_string($value) && !preg_match('/./u', $value)) || (is_object($value) && is_callable([$value, '__toString'])))
{
- $value = $this->handler->convertToUtf8(strval($value));
+ $value = $this->handler->convertToUtf8(strval($value), null, $options[self::UNHTML_ENTITIES]);
}
try
@@ -112,7 +128,7 @@
throw new \InvalidArgumentException($e->getMessage() . " [$field]", $e->getCode(), $e);
}
- if (!$vf->applyValueConstraints($value, $column['type'], $column, $error, $options['forceConstraint']))
+ if (!$vf->applyValueConstraints($value, $column['type'], $column, $error, $options[self::FORCE_CONSTRAINT]))
{
throw new \InvalidArgumentException("Constraint error for $field: " . $error);
}
I'm going to leave it in there, because if we want to unhtml something that we are also utf8-converting, we would use the entities translation system fromRemember that "convertToUtf8" is only called for badly encoded strings (because of!preg_match('/./u', $value))
which for some reason was added in 2.0.3).
I think the unhtml call needs to be moved outside of "convertToUtf8".
utf8_unhtml()
, whereas if there is no utf8 conversion, we'd use htmlspecialchars_decode()
if ($options[self::CONVERT_UTF8])
{
if ((is_string($value) && !preg_match('/./u', $value)) || (is_object($value) && is_callable([$value, '__toString'])))
{
$value = $this->handler->convertToUtf8(strval($value), null, $options[self::UNHTML_ENTITIES]);
}
try
{
$value = $vf->castValueToType($value, $column['type'], $column);
}
catch (\Exception $e)
{
if (is_string($originalValue) && !preg_match('/./u', $originalValue))
{
$value = utf8_bad_replace($originalValue);
}
}
}
else if ($options[self::UNHTML_ENTITIES] && (is_string($value) || (is_object($value) && is_callable([$value, '__toString']))))
{
$value = htmlspecialchars_decode($value);
}
if ($options[self::CONVERT_UTF8])
{
if ($this->isStringy($value))
{
if (!$this->isValidUtf8($value))
{
$value = $this->handler->convertToUtf8(strval($value), null, $options[self::UNHTML_ENTITIES]);
}
else if ($options[self::UNHTML_ENTITIES])
{
$value = htmlspecialchars_decode(strval($value));
}
}
try
{
$value = $vf->castValueToType($value, $column['type'], $column);
}
catch (\Exception $e)
{
if (is_string($originalValue) && !$this->isValidUtf8($originalValue))
{
$value = utf8_bad_replace($originalValue);
}
}
}
else if ($options[self::UNHTML_ENTITIES] && $this->isStringy($value))
{
$value = htmlspecialchars_decode(strval($value));
}
"for some reason" = https://xenforo.com/community/threa...-xf-import-data-entityemulator-php-93.143897/Remember that "convertToUtf8" is only called for badly encoded strings (because of!preg_match('/./u', $value))
which for some reason was added in 2.0.3).
We use essential cookies to make this site work, and optional cookies to enhance your experience.