aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Zaretskii2006-08-04 10:42:41 +0000
committerEli Zaretskii2006-08-04 10:42:41 +0000
commit65c6c6b6ca9b39fc0d06621db620c5b235e7d45f (patch)
treec384afd34cd2bfba65995334379079d1be8faa6e
parent6f64cebf164a4a613f445aa32e70e95ba6a50d45 (diff)
downloademacs-65c6c6b6ca9b39fc0d06621db620c5b235e7d45f.tar.gz
emacs-65c6c6b6ca9b39fc0d06621db620c5b235e7d45f.zip
(Formatting Strings): Warn against arbitrary strings as first arg to `format'.
-rw-r--r--lispref/ChangeLog5
-rw-r--r--lispref/strings.texi12
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 @@
12006-08-04 Eli Zaretskii <eliz@gnu.org>
2
3 * strings.texi (Formatting Strings): Warn against arbitrary
4 strings as first arg to `format'.
5
12006-07-31 Thien-Thi Nguyen <ttn@gnu.org> 62006-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
702The characters in @var{string}, other than the format specifications, 702The characters in @var{string}, other than the format specifications,
703are copied directly into the output; if they have text properties, 703are copied directly into the output; if they have text properties,
704these 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
722specifications, you should @emph{never} pass an arbitrary string as
723the first argument. This is particularly true when the string is
724generated by some Lisp code. Unless the string is @emph{known} to
725never include any @samp{%} characters, pass @code{"%s"}, described
726below, 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
723format specifications correspond to successive values from 733format 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}