Skip to content

Commit e1b04e0

Browse files
committed
Fix incorrectly encoding quotes for Vizy field content
1 parent 8cee7c1 commit e1b04e0

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/fields/VizyField.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,11 +218,31 @@ public function getInputHtml($value, ElementInterface $element = null): string
218218
'"' . $view->namespaceInputName($this->handle) . '"' .
219219
');');
220220

221+
$rawNodes = $value->getRawNodes();
222+
223+
// Normalise the content a little to handle special characters.
224+
// TODO: This is temporary, but helps transition people with issues _now_ but is
225+
// handled in `Nodes::serializeContent()` and `StringHelper::htmlEncode($text, ENT_NOQUOTES)`
226+
foreach ($rawNodes as $rawNodeKey => $rawNode) {
227+
$content = $rawNode['content'] ?? [];
228+
229+
foreach ($content as $contentKey => $block) {
230+
// We only want to modify simple nodes and their text content, not complicated
231+
// nodes like VizyBlocks, which could mess things up as fields control their content.
232+
$text = $block['text'] ?? '';
233+
234+
// Decode some HTML entities
235+
$text = StringHelper::htmlDecode($text);
236+
237+
$rawNodes[$rawNodeKey]['content'][$contentKey]['text'] = $text;
238+
}
239+
}
240+
221241
return $view->renderTemplate('vizy/field/input', [
222242
'id' => $id,
223243
'name' => $this->handle,
224244
'field' => $this,
225-
'value' => Json::encode($value->getRawNodes(), JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_QUOT),
245+
'value' => Json::encode($rawNodes, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_QUOT),
226246
'settings' => Json::encode($settings, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_QUOT),
227247
]);
228248
}

src/helpers/Nodes.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,9 @@ public static function serializeContent($rawNode)
116116
$text = LitEmoji::unicodeToShortcode($text);
117117

118118
// Escape any HTML tags used in the text. Maybe we're writing HTML in text?
119+
// But don't encode quotes, things like `"` are invalid in JSON
119120
$text = StringHelper::htmlDecode($text);
120-
$text = StringHelper::htmlEncode($text);
121+
$text = StringHelper::htmlEncode($text, ENT_NOQUOTES);
121122

122123
$rawNode['content'][$key]['text'] = $text;
123124

0 commit comments

Comments
 (0)