diff options
author | Eli Zaretskii <eliz@gnu.org> | 2022-01-22 11:58:05 +0200 |
---|---|---|
committer | Eli Zaretskii <eliz@gnu.org> | 2022-01-22 11:58:05 +0200 |
commit | 682b6df6bfc7af98a28b54bd925cd33dead2c25d (patch) | |
tree | 3cae6a2583336037b7aea8091f740ebf342b73a0 /lisp/international/textsec.el | |
parent | ebe334cdc234de2897263aed4c05ac7088c11857 (diff) | |
download | emacs-682b6df6bfc7af98a28b54bd925cd33dead2c25d.tar.gz emacs-682b6df6bfc7af98a28b54bd925cd33dead2c25d.tar.bz2 emacs-682b6df6bfc7af98a28b54bd925cd33dead2c25d.zip |
Improve detection of suspicious uses of bidi controls
* lisp/international/textsec.el
(textsec-bidi-controls-suspicious-p): New function.
(textsec-name-suspicious-p): Use it.
* test/lisp/international/textsec-tests.el (test-suspicious-name):
Enable the test that was previously failing with
'bidi-find-overridden-directionality'.
Diffstat (limited to 'lisp/international/textsec.el')
-rw-r--r-- | lisp/international/textsec.el | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/lisp/international/textsec.el b/lisp/international/textsec.el index 223c0d5c92f..adef64bfdf0 100644 --- a/lisp/international/textsec.el +++ b/lisp/international/textsec.el @@ -287,6 +287,22 @@ certain other unusual mixtures of characters." ((string-match-p "\\`\\.\\|\\.\\'\\|\\.\\." local) (format "`%s' contains invalid dots" local)))) +(defun textsec-bidi-controls-suspicious-p (string) + "Return non-nil of STRING uses bidi controls in suspicious ways. +If STRING doesn't include any suspicious uses of bidirectional +formatting control characters, return nil. Otherwise, return the +index of the first character in STRING affected by such suspicious +use of bidi controls. If the returned value is beyond the length +of STRING, it means any text following STRING on display might be +affected by bidi controls in STRING." + (with-temp-buffer + ;; We add a string that's representative of some text that could + ;; follow STRING, with the purpose of detecting residual bidi + ;; state at end of STRING which could then affect the following + ;; text. + (insert string "a1א:!") + (bidi-find-overridden-directionality 1 (point-max) nil))) + (defun textsec-name-suspicious-p (name) "Say whether NAME looks suspicious. NAME is (for instance) the free-text display name part of an @@ -310,10 +326,11 @@ other unusual mixtures of characters." ?\N{arabic letter mark}))))) name) ;; We have bidirectional formatting characters, but check - ;; whether they affect LTR characters. If not, it's not - ;; suspicious. - (bidi-find-overridden-directionality 0 (length name) name)) - (format "The string contains bidirectional control characters")) + ;; whether they affect any other characters in suspicious + ;; ways. If not, NAME is not suspicious. + (fixnump (textsec-bidi-controls-suspicious-p name))) + (format "`%s' contains suspicious uses of bidirectional control characters" + name)) ((textsec-suspicious-nonspacing-p name)))) (defun textsec-suspicious-nonspacing-p (string) |