aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorDmitry Antipov <[email protected]>2014-06-25 14:36:51 +0400
committerDmitry Antipov <[email protected]>2014-06-25 14:36:51 +0400
commit5697ca55cb79817a6704c344cc76d866ee2e1699 (patch)
tree3d9cace5c0dd430485eb16697cb6c045553eb3ae /test
parent9a214b9800b7c01d8a473a2564e8f57215990b24 (diff)
Do not allow out-of-range character position in Fcompare_strings.
* src/fns.c (validate_subarray): Add prototype. (Fcompare_substring): Use validate_subarray to check ranges. Adjust comment to mention that the semantics was changed. Also see http://lists.gnu.org/archive/html/emacs-devel/2014-06/msg00447.html. * lisp/files.el (dir-locals-find-file, file-relative-name): * lisp/info.el (Info-complete-menu-item): * lisp/minibuffer.el (completion-table-subvert): Prefer string-prefix-p to compare-strings to avoid out-of-range errors. * lisp/subr.el (string-prefix-p): Adjust to match strict range checking in compare-strings. * test/automated/fns-tests.el (fns-tests-compare-string): New test.
Diffstat (limited to 'test')
-rw-r--r--test/ChangeLog4
-rw-r--r--test/automated/fns-tests.el31
2 files changed, 35 insertions, 0 deletions
diff --git a/test/ChangeLog b/test/ChangeLog
index 08492dd4c8..3cb03b9f2f 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,7 @@
+2014-06-25 Dmitry Antipov <[email protected]>
+
+ * automated/fns-tests.el (fns-tests-compare-string): New test.
+
2014-06-24 Michael Albinus <[email protected]>
* automated/tramp-tests.el (tramp-test26-process-file): Extend test
diff --git a/test/automated/fns-tests.el b/test/automated/fns-tests.el
index 21a9e4536a..461995b602 100644
--- a/test/automated/fns-tests.el
+++ b/test/automated/fns-tests.el
@@ -69,3 +69,34 @@
(nreverse A)
(should (equal [nil nil nil nil nil t t t t t] (vconcat A)))
(should (equal [t t t t t nil nil nil nil nil] (vconcat (nreverse A))))))
+
+(ert-deftest fns-tests-compare-strings ()
+ (should-error (compare-strings))
+ (should-error (compare-strings "xyzzy" "xyzzy"))
+ (should-error (compare-strings "xyzzy" 0 10 "zyxxy" 0 5))
+ (should-error (compare-strings "xyzzy" 0 5 "zyxxy" -1 2))
+ (should-error (compare-strings "xyzzy" 'foo nil "zyxxy" 0 1))
+ (should-error (compare-strings "xyzzy" 0 'foo "zyxxy" 2 3))
+ (should-error (compare-strings "xyzzy" 0 2 "zyxxy" 'foo 3))
+ (should-error (compare-strings "xyzzy" nil 3 "zyxxy" 4 'foo))
+ (should (compare-strings "" nil nil "" nil nil))
+ (should (compare-strings "" 0 0 "" 0 0))
+ (should (compare-strings "test" nil nil "test" nil nil))
+ (should (compare-strings "test" nil nil "test" nil nil t))
+ (should (compare-strings "test" nil nil "test" nil nil nil))
+ (should (compare-strings "Test" nil nil "test" nil nil t))
+ (should (= (compare-strings "Test" nil nil "test" nil nil) -1))
+ (should (= (compare-strings "Test" nil nil "test" nil nil) -1))
+ (should (= (compare-strings "test" nil nil "Test" nil nil) 1))
+ (should (= (compare-strings "foobaz" nil nil "barbaz" nil nil) 1))
+ (should (= (compare-strings "barbaz" nil nil "foobar" nil nil) -1))
+ (should (= (compare-strings "foobaz" nil nil "farbaz" nil nil) 2))
+ (should (= (compare-strings "farbaz" nil nil "foobar" nil nil) -2))
+ (should (compare-strings "abcxyz" 0 2 "abcprq" 0 2))
+ (should (compare-strings "abcxyz" 0 -3 "abcprq" 0 -3))
+ (should (= (compare-strings "abcxyz" 0 6 "abcprq" 0 6) 4))
+ (should (= (compare-strings "abcprq" 0 6 "abcxyz" 0 6) -4))
+ (should (compare-strings "xyzzy" -3 4 "azza" -3 3))
+ (should (compare-strings "こんにちはコンニチハ" nil nil "こんにちはコンニチハ" nil nil))
+ (should (= (compare-strings "んにちはコンニチハこ" nil nil "こんにちはコンニチハ" nil nil) 1))
+ (should (= (compare-strings "こんにちはコンニチハ" nil nil "んにちはコンニチハこ" nil nil) -1)))