Closed (fixed)
Project:
Page Manager
Version:
8.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
15 Feb 2016 at 12:52 UTC
Updated:
3 Sep 2016 at 19:24 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
berdirComment #3
tduong commentedIt seems like it displays the title wrong already when creating a simple node with special chars in the title. Uploaded an edited test form an existing one just as starting point. Will fail.
Comment #5
tduong commentedJust for now we've tried to fix the page title rendering with the change in interdiff, but the wrong encoding at the beginning of the test still exists.
Comment #7
tduong commentedTest fails because in that node view it's just on first encoding and it displays the special & as &. Test updated.
Comment #8
tim.plunkettYou don't need a comment like this
What's the difference between getTitle() and label()?
Comment #9
tduong commented#8.1 done
#8.2 no difference actually, but maybe would be more sensitive to make both of them getTitle() and specify (on node creation) that we are testing for title with special HTML characters (?). Changed it in label() for now.
Comment #10
berdirThis seems to indicate that our fix is not consistent with the default node page title.
For core, it is encoded once. In our case, it's not.
Please expand the test title to something like
First & <Second>. Those should be displayed on the page and not treated as an HTML tag.Comment #11
tduong commentedAdjusted test and reverted fix in PageBlockDisplayVariant::renderPageTitle().
Comment #12
tduong commentedDiscussed with @berdir and the last assertRaw needs to be more specific. Readd fix in PageBlockDisplayVariant::renderPageTitle(). What we expect is both test and test_only patches to fail.
Comment #15
tduong commented@berdir suggested to put
Markup::create(Html::escape( .. ))around the previous return value in PageBlockDisplayVariant::renderPageTitle(). This should make the test to pass.Comment #17
berdirSo this works, but it's really ugly.
related core issues:
#2580723: Fix token system confusion, with new function Token::replacePlain()
#2662296: There's no way to trust Token::replace() @return
Comment #18
tduong commentedComment #19
tim.plunkettComment #20
arla commentedAnd maybe add a comment excusing the nesting like "Special characters in token values are encoded during replacement, so recode them and mark it as safe to avoid autoescape which would result in double encoding."
<em>First</em> & <Second>would becomeFirst & <Second>?Comment #21
berdir1. I think they don't, this was the only thing that worked for us.
2. Yes, lets split it up.
3. Agree with adding that. would get escaped as well I *think*, we'll see.
Comment #22
arla commentedComment #23
arla commentedThem cancelling each other out.
Comment #24
berdirThey don't really cancel themself out in general. renderFromHtml() first strips HTML tags.
The reason those here are actually kept is because token replace does weird things to the replacement values and enforces them to get escaped. Then they're put into the string and at that point, are being escaped. And then later, escaped again.
The problem is, that only happens for token replacements. What we need to do in the test is extend it and once also use that node title directly in page manager. Then you can see that your latest patch doesn't escape anymore at all.
But neither does the previous patch work, at least not in a consistent way, as it actually removes the tag then.
I found a new approach that seems to be working consistently, by escaping the input text first as well and then creating a Markup object. I think token should offer something like that as an API.
Comment #25
berdirAdded a @todo on the core issue
Comment #26
tim.plunkettLooks great! Thanks for adding the @todo.
Comment #27
arla commentedLooks good to me too!
Comment #28
arla commentedLooks like with the latest patch, the HTML
<title>content is broken.Comment #29
arla commentedAh, what I was seeing was that $page_title was "", in which case replace() returned the unmodified HtmlEscapedText object. Later, in template_preprocess_html(), the
if (!empty($variables['page']['#title'])) {condition passed, resulting in the empty "" being used as title rather than the default "Home".Not sure what the most technically correct solution to that would be, but a simple option is to cast the replace() result to string.
Comment #30
arla commentedAdded the string cast and created a test to prove it's needed. The test-only patch adds that test to the previous patch, but does not add the string cast.
Comment #32
berdirBump :)
Comment #33
japerryThis looks good and tested good by me. Fixed!