Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Pls’s picture

Status: Needs review » Reviewed & tested by the community

Patch works great and fixes the problem for markup.

hass’s picture

Status: Reviewed & tested by the community » Needs work

What are you trying to do here? I do not understand the substr logic. Do you like to use strip_tags() for the message?

Liam Morland’s picture

The call to substr() is just a quick way to determine if the "message" actually a moderation form which shouldn't be wrapped in an em element.

hass’s picture

Looks not reliable...

Liam Morland’s picture

How about:

if ($message['message'] === check_plain($message['message'])) {
stevector’s picture

Status: Needs work » Needs review
FileSize
981 bytes

Thanks for identifying this!

The invalid HTML is definitely a problem and if a patch like this is the best way to fix it then we'll go with it. I'm posting a revised patch here. It checks for '

I'm open to any opinions on which is more appropriate.

Check_plain() is not an option because that would wreck the form's markup.

Liam Morland’s picture

Yes, that would work too.

Here is a more robust approach.

stevector’s picture

Liam, I'm not following that last patch.

I also now see that my last comment had invalid html in it and was thus cut off!

I tried to say

Thanks for identifying this!

The invalid HTML is definitely a problem and if a patch like this is the best way to fix it then we'll go with it. I'm posting a revised patch here. It checks for '<form' because it's possible that a link would be used here. I've also switch the strpos instead of substr because that felt more straight forward.

I'm open to any opinions on which is more appropriate.

Check_plain() is not an option because that would wreck the form's markup.

Liam Morland’s picture

check_plain() is just used to check if the message is plain text or HTML. If it is HTML, it goes through as-is. If it is plain text, it gets wrapped in an em element.

My last patch uses CSS instead of wrapping messages in an em element. It looks the same, but has slightly different semantics.

Your patch in #6 would work for the form. If a message had any other block-level HTML, it wouldn't work. The check_plain() or CSS approaches would work for any content.

hass’s picture

check_plain() is just used to check if the message is plain text or HTML. If it is HTML, it goes through as-is. If it is plain text, it gets wrapped in an em element.

Ahhh, NO! All tags are converted to safe HTML. This means < become &lt; and so on. If a %placeholder inside t() is used it get's surrounded by <em> (format_string).

Dave Reid’s picture

Related, I'm not sure why this code is continuing to use t() since there's no real words in this text. I think this should just be calling drupal_placeholder() manually?

Liam Morland’s picture

Ahhh, NO! All tags are converted to safe HTML.

Yes, but the output of check_plain() is not put into the page. The only thing that is done with it is it the compared to the original string. If $message and check_plain($message) are the same, then it is safe to wrap it in an em element.

Related, I'm not sure why this code is continuing to use t()

Yes, it is the message and the label that needs to be translated. Thanks for noticing that.

Liam Morland’s picture

Here is an updated patch that removes the call to t() which doesn't do anything anyway because there is no text in that string. (If text is not being translated, that is a different issue and removing t() does not have any effect on that.)

hass’s picture

I cannot speak 100% for arabic/hebrew/chinese/japanese, but it's possible that we need to keep this wrapped in t().

Liam Morland’s picture

Could be. In that case, use the patch in #7. The only difference is the wrapping in t().

Liam Morland’s picture

Issue summary: View changes
FileSize
1.09 KB

Reroll.

Liam Morland’s picture

Sorry, this is the reroll.

The last submitted patch, 16: workbench_moderation_invalid_html.patch, failed testing.

Liam Morland’s picture

The patch in #17 is fine; the error is about the patch in #16.

Liam Morland’s picture

Liam Morland’s picture

Liam Morland’s picture