On a fresh Drupal 8.2.3 install, using tablefield 8.x-2.x-dev.
1. Create a tablefield field on any content type.
2. Create some content, in any of the table cells enter "John's data"
3. View the node.
This is being output as "john's data" instead of "John's data". Looking at the source code the cell contains "john's data", so it looks like the HTML escaping process is being run twice.
Around line 54 of TablefieldFormatter.php I can see the following line:
'data' => empty($table->format) ? Html::escape($cell) : check_markup($cell, $table->format),
It looks like you don't need to run Html::escape here, as it will be run again on the field when rendered.
Comments
Comment #2
fdverwoerd commentedYes, simple "word's" gets escaped because the object `$table->format` is not set (Plain). I changed the 'escaping' to decodeEntities in a patch.
Comment #3
lolandese commentedThere is now a patch to review.
Comment #4
hgoto commentedI tested the patch #2. It works well. Yet, I believe we can rely on the Twig autoescaping.
https://www.drupal.org/node/2296163
So the line can be simply like
without using
Html::escape(), I think. @fdverwoerd, if you don't mind, could you please update the patch?Comment #5
fdverwoerd commentedHi @hgoto,
I've updated the patch without escaping the 'cell', and it still works for me!
Thanks, need's review again.
Comment #6
hgoto commented@fdverwoerd thank you! I tested the patch #5 and it works well for me.
Nitpick.
Htmlis no longer used in TablefieldFormatter.php and maybe we can remove the following line as well?Comment #7
fdverwoerd commentedTrue, it isn't used anymore indeed. I've removed it and updated patch.
Comment #8
hgoto commentedI tested the patch #7 and it works well. I believe it's OK to mark this RTBC. Thanks!
Comment #9
hgoto commentedComment #10
StevenWill commentedI have also tested patch #7 and it works for me. Also fixed a issue with &.
Comment #12
lolandese commentedThanks for your contribution.