diff options
| author | Eli Zaretskii | 2006-08-04 10:42:41 +0000 |
|---|---|---|
| committer | Eli Zaretskii | 2006-08-04 10:42:41 +0000 |
| commit | 65c6c6b6ca9b39fc0d06621db620c5b235e7d45f (patch) | |
| tree | c384afd34cd2bfba65995334379079d1be8faa6e | |
| parent | 6f64cebf164a4a613f445aa32e70e95ba6a50d45 (diff) | |
| download | emacs-65c6c6b6ca9b39fc0d06621db620c5b235e7d45f.tar.gz emacs-65c6c6b6ca9b39fc0d06621db620c5b235e7d45f.zip | |
(Formatting Strings): Warn against arbitrary strings as first arg to `format'.
| -rw-r--r-- | lispref/ChangeLog | 5 | ||||
| -rw-r--r-- | lispref/strings.texi | 12 |
2 files changed, 16 insertions, 1 deletions
diff --git a/lispref/ChangeLog b/lispref/ChangeLog index f3f3037e4d1..eb1fd9797c2 100644 --- a/lispref/ChangeLog +++ b/lispref/ChangeLog | |||
| @@ -1,3 +1,8 @@ | |||
| 1 | 2006-08-04 Eli Zaretskii <eliz@gnu.org> | ||
| 2 | |||
| 3 | * strings.texi (Formatting Strings): Warn against arbitrary | ||
| 4 | strings as first arg to `format'. | ||
| 5 | |||
| 1 | 2006-07-31 Thien-Thi Nguyen <ttn@gnu.org> | 6 | 2006-07-31 Thien-Thi Nguyen <ttn@gnu.org> |
| 2 | 7 | ||
| 3 | * text.texi (Clickable Text): Mention `help-echo' text property. | 8 | * text.texi (Clickable Text): Mention `help-echo' text property. |
diff --git a/lispref/strings.texi b/lispref/strings.texi index 46c01982f32..12abc38ee02 100644 --- a/lispref/strings.texi +++ b/lispref/strings.texi | |||
| @@ -701,7 +701,6 @@ arguments @var{objects} are the computed values to be formatted. | |||
| 701 | 701 | ||
| 702 | The characters in @var{string}, other than the format specifications, | 702 | The characters in @var{string}, other than the format specifications, |
| 703 | are copied directly into the output; if they have text properties, | 703 | are copied directly into the output; if they have text properties, |
| 704 | these are copied into the output also. | ||
| 705 | @end defun | 704 | @end defun |
| 706 | 705 | ||
| 707 | @cindex @samp{%} in format | 706 | @cindex @samp{%} in format |
| @@ -719,6 +718,17 @@ For example: | |||
| 719 | @end group | 718 | @end group |
| 720 | @end example | 719 | @end example |
| 721 | 720 | ||
| 721 | Since @code{format} interprets @samp{%} characters as format | ||
| 722 | specifications, you should @emph{never} pass an arbitrary string as | ||
| 723 | the first argument. This is particularly true when the string is | ||
| 724 | generated by some Lisp code. Unless the string is @emph{known} to | ||
| 725 | never include any @samp{%} characters, pass @code{"%s"}, described | ||
| 726 | below, as the first argument, and the string as the second, like this: | ||
| 727 | |||
| 728 | @example | ||
| 729 | (format "%s" @var{arbitrary-string}) | ||
| 730 | @end example | ||
| 731 | |||
| 722 | If @var{string} contains more than one format specification, the | 732 | If @var{string} contains more than one format specification, the |
| 723 | format specifications correspond to successive values from | 733 | format specifications correspond to successive values from |
| 724 | @var{objects}. Thus, the first format specification in @var{string} | 734 | @var{objects}. Thus, the first format specification in @var{string} |