The current documentation for format_string() emphasizes that it is to be used for "sanitizing" text but that's not really a complete description. Even if you trust the source of your text, you still want to run it through e.g. check_plain() if there's any chance it might contain a character that will be erroneously interpreted as HTML, and format_string() is a good way to do that.

Thus, we really should encourage people to use this function regardless of whether untrusted user input is involved. (See discussion in #500866: [META] remove t() from assert message.)

The attached patch is a first pass at trying to clarify the documentation in this regard and otherwise make some small improvements to it.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

David_Rothstein’s picture

Status: Active » Needs review
FileSize
2.5 KB

Here's the patch.

jhodgdon’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs backport to D7

I think this is an excellent update to the documentation of this function. Thanks!

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed to 8.x and 7.x. Thanks!

David_Rothstein’s picture

Status: Fixed » Needs review
FileSize
823 bytes

Hm, I think I managed to tell people to use this function in one paragraph and then tell them not to use it the next.

This patch tries to clarify that...

jhodgdon’s picture

Status: Needs review » Reviewed & tested by the community

I have no problem with that addition to the documentation in #4, although I don't think it's totally necessary. :)

tim.plunkett’s picture

jhodgdon’s picture

Status: Reviewed & tested by the community » Fixed

Committed to 7.x and 8.x. Thanks!

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

Fix typo.