From: Eli Zaretskii Date: Sat, 6 Nov 2021 10:33:26 +0000 (+0200) Subject: Improve detection of suspicious reordering in source code X-Git-Tag: emacs-29.0.90~3671^2~197 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=26089c8c446de4851143a42b2005844d152e8e99;p=emacs.git Improve detection of suspicious reordering in source code * src/bidi.c (bidi_find_first_overridden): Detect suspiciously reordered EN types as well. * test/src/xdisp-tests.el (xdisp-tests--find-directional-overrides-case-1): Rename from 'xdisp-tests--find-directional-overrides'. (xdisp-tests--find-directional-overrides-case-2): New test. --- diff --git a/src/bidi.c b/src/bidi.c index 3cdcd7da1b5..511b4602fec 100644 --- a/src/bidi.c +++ b/src/bidi.c @@ -3589,10 +3589,11 @@ bidi_find_first_overridden (struct bidi_it *bidi_it) || (type == STRONG_L && (bidi_it->orig_type == STRONG_R || bidi_it->orig_type == STRONG_AL)) - /* Detect strong L or R types that were pushed into higher - embedding levels (and will thus reorder) by explicit - embeddings and isolates. */ - || (bidi_it->orig_type == STRONG_L + /* Detect strong L or R types or WEAK_EN types that were + pushed into higher embedding levels (and will thus + reorder) by explicit embeddings and isolates. */ + || ((bidi_it->orig_type == STRONG_L + || bidi_it->orig_type == WEAK_EN) && bidi_it->level_stack[bidi_it->stack_idx].level > max_l2r) || ((bidi_it->orig_type == STRONG_R || bidi_it->orig_type == STRONG_AL) diff --git a/test/src/xdisp-tests.el b/test/src/xdisp-tests.el index a385ded8e1d..4a87f19cabb 100644 --- a/test/src/xdisp-tests.el +++ b/test/src/xdisp-tests.el @@ -99,7 +99,7 @@ (width-in-chars (/ (car size) char-width))) (should (equal width-in-chars 3))))) -(ert-deftest xdisp-tests--find-directional-overrides () +(ert-deftest xdisp-tests--find-directional-overrides-case-1 () (with-temp-buffer (insert "\ int main() { @@ -114,4 +114,24 @@ int main() { nil) 46)))) +(ert-deftest xdisp-tests--find-directional-overrides-case-2 () + (with-temp-buffer + (insert "\ +#define is_restricted_user(user) \\ + !strcmp (user, \"root\") ? 0 : \\ + !strcmp (user, \"admin\") ? 0 : \\ + !strcmp (user, \"superuser‮⁦? 0 : 1⁩ ⁦\")⁩‬ + +int main () { + printf (\"root: %d\\n\", is_restricted_user (\"root\")); + printf (\"admin: %d\\n\", is_restricted_user (\"admin\")); + printf (\"superuser: %d\\n\", is_restricted_user (\"superuser\")); + printf (\"luser: %d\\n\", is_restricted_user (\"luser\")); + printf (\"nobody: %d\\n\", is_restricted_user (\"nobody\")); +}") + (goto-char (point-min)) + (should (eq (bidi-find-overridden-directionality (point-min) (point-max) + nil) + 140)))) + ;;; xdisp-tests.el ends here