To reproduce the issue, create a webform with a title that contains an apostrophe, e.g. Purchase KNIME Beginner's Luck and also enable the preview of the form.
The title is discplayed correctly on the form itself, but on the preview page it is broken and displays like Purchase KNIME Beginner's Luck.
Proposed solution
I found out that this is happening in WebformSubmissionForm::getWebformSetting() in this line:
return $this->tokenManager->replace($this->settings[$name], $this->getEntity());
This returns a MarkupElement where the original value was a plain string.
I checked with other modules who do similar things and found in Metatags, that they do the following:
return PlainTextOutput::renderFromHtml(htmlspecialchars_decode($this->tokenManager->replace($this->settings[$name], $this->getEntity())));
With this, the string value remains a string value and all subsequent issues are gone. I'll submit a patch in a minute.
Comments
Comment #2
jurgenhaasAttached patch solves this problem.
Comment #3
jrockowitz commentedPatch needs test coverage.
Comment #5
jurgenhaasCan you provide some guidance please? I'm stuck otherwise.
Comment #6
jrockowitz commentedI am almost certain #2895140: Email handler field(s) convert special chars to HTML code is related and the patch is also fixing this issue and is possibly the better solution. Please see if the patch fixes your problem.
For test coverage.
@see \Drupal\webform\Tests\WebformTokenSubmissionValue
You should be able to update tests/modules/webform_test/config/install/webform.webform.test_token_submission_value.yml and add some special characters to the values.
Comment #7
jrockowitz commentedComment #8
jrockowitz commented@jurgenhaas Your patch was right on the money. The token issue is not related.
I just added some tests.
Comment #9
jurgenhaas@jrockowitz thank you so much, I'm glad the patch is helpful and thanks for adding the tests. I've looked at them and I'm a bit confused that assertRaw checks to get the HTML characters, I thought that's exactly what we don't want. Isn't the purpose of this to exactly avoid that?
Comment #10
jrockowitz commentedThe issue was the #title's special characters were being double encoded.
If you remove
$form['#title'] = PlainTextOutput::renderFromHtml($this->getWebformSetting('preview_title'));the tests will break with'becoming'Comment #12
jrockowitz commentedI committed the patch. Please download the latest dev release to review.