Skip to:

Opened 14 years ago

Closed 14 years ago

#2983 closed defect (bug) (fixed)

sprintf content needs to be in single quotes

Reported by: boonebgorges's profile boonebgorges Owned by:
Milestone: 1.5 Priority: major
Severity: Version:
Component: Core Keywords:


When you use the swappable characters notation for sprintf (%1$s vs %s), the pattern needs to be enclosed in single quotes, not double quotes. Otherwise PHP will attempt to read the $s as a variable, resulting in a PHP warning (because $s has not been defined) and, more importantly, a failed replacement.

Change History (4)

#1 @boonebgorges
14 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [3614]) Replaces sprintf double quotes with single quotes to avoid substitution problems. Fixes #2983

#2 @wpmuguru
14 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

The \n only gets coverted to a newline if it is in double quotes. In single quotes they are taken as literals instead of a control sequence.

#3 @boonebgorges
14 years ago

Right you are, wpmuguru. For now I will switch those instances back to double quotes. When I do a full sweep (#2703) I will probably end up escaping the swappable characters so that we can still use that construction, eg %1\$s.

#4 @boonebgorges
14 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

(In [3629]) Swaps single quotes with double quotes within sprintf in instances where unix line breaks need to be processed. Reverts part of [3614]. Fixes #2983. Props wpmuguru

Note: See TracTickets for help on using tickets.