Make read-char-by-name signal an error for invalid input.
authorChong Yidong <cyd@gnu.org>
Fri, 21 Dec 2012 07:51:33 +0000 (15:51 +0800)
committerChong Yidong <cyd@gnu.org>
Fri, 21 Dec 2012 07:51:33 +0000 (15:51 +0800)
* international/mule-cmds.el (read-char-by-name): Signal an error
if the user does not supply a valid character.

* editfns.c (Finsert_char): Since read-char-by-name now signals an
error for invalid chars, don't check for a nil return value.

Fixes: debbugs:13177

lisp/ChangeLog
lisp/international/mule-cmds.el
src/ChangeLog
src/editfns.c

index cd7dd97..a25836d 100644 (file)
@@ -5,6 +5,9 @@
 
 2012-12-21  Chong Yidong  <cyd@gnu.org>
 
+       * international/mule-cmds.el (read-char-by-name): Signal an error
+       if the user does not supply a valid character (Bug#13177).
+
        * simple.el (transpose-subr-1): Preserve marker positions by
        changing the insertion sequence (Bug#13122).
 
index f324446..07b0f91 100644 (file)
@@ -2953,14 +2953,18 @@ point or a number in hash notation, e.g. #o21430 for octal,
             (let ((completion-ignore-case t))
               (if (eq action 'metadata)
                   '(metadata (category . unicode-name))
-                (complete-with-action action (ucs-names) string pred)))))))
-    (cond
-     ((string-match-p "\\`[0-9a-fA-F]+\\'" input)
-      (string-to-number input 16))
-     ((string-match-p "\\`#" input)
-      (read input))
-     (t
-      (cdr (assoc-string input (ucs-names) t))))))
+                (complete-with-action action (ucs-names) string pred))))))
+        (char
+         (cond
+          ((string-match-p "\\`[0-9a-fA-F]+\\'" input)
+           (string-to-number input 16))
+          ((string-match-p "\\`#" input)
+           (read input))
+          (t
+           (cdr (assoc-string input (ucs-names) t))))))
+    (unless (characterp char)
+      (error "Invalid character"))
+    char))
 
 (define-obsolete-function-alias 'ucs-insert 'insert-char "24.3")
 (define-key ctl-x-map "8\r" 'insert-char)
index f9c629c..24f32f1 100644 (file)
@@ -1,3 +1,8 @@
+2012-12-21  Chong Yidong  <cyd@gnu.org>
+
+       * editfns.c (Finsert_char): Since read-char-by-name now signals an
+       error for invalid chars, don't check for a nil return value.
+
 2012-12-20  Dmitry Antipov  <dmantipov@yandex.ru>
 
        Avoid calls to CHAR_TO_BYTE if byte position is known.
index d7fe1c1..bb5cc43 100644 (file)
@@ -2361,10 +2361,9 @@ usage: (insert-before-markers-and-inherit &rest ARGS)  */)
 }
 \f
 DEFUN ("insert-char", Finsert_char, Sinsert_char, 1, 3,
-       "(list (or (read-char-by-name \"Insert character (Unicode name or hex): \")\
-         (error \"You did not specify a valid character\"))\
-      (prefix-numeric-value current-prefix-arg)\
-      t))",
+       "(list (read-char-by-name \"Insert character (Unicode name or hex): \")\
+              (prefix-numeric-value current-prefix-arg)\
+              t))",
        doc: /* Insert COUNT copies of CHARACTER.
 Interactively, prompt for CHARACTER.  You can specify CHARACTER in one
 of these ways: