]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix bugs, inefficiencies and bad style in regexps
authorMattias Engdegård <mattiase@acm.org>
Thu, 16 Apr 2020 09:04:24 +0000 (11:04 +0200)
committerMattias Engdegård <mattiase@acm.org>
Thu, 16 Apr 2020 10:14:38 +0000 (12:14 +0200)
Found by relint.  See discussion at
https://lists.gnu.org/archive/html/emacs-devel/2020-04/msg00265.html

* lisp/org/org-table.el (org-table-finish-edit-field):
* lisp/arc-mode.el (archive-rar-summarize):
Avoid wrapped subsumption in repeated sequences.
* lisp/erc/erc-dcc.el (erc-dcc-ctcp-query-send-regexp): Replace
inefficient repeated empty-matching expression with a plain greedy
form.
(erc-dcc-handle-ctcp-send): Adjust group numbers.
* lisp/net/puny.el (puny-encode-domain): Fix fast-path shortcut
pattern so that it actually works as intended.
* lisp/progmodes/gdb-mi.el (gdb-control-commands-regexp):
* lisp/vc/diff-mode.el (diff-imenu-generic-expression):
Remove superfluous backslashes.
* lisp/progmodes/scheme.el (scheme-imenu-generic-expression):
Correct confused definition-matching pattern which would match more
than intended.
* lisp/textmodes/sgml-mode.el (sgml-tag-name-re): Avoid inefficient
matching by using the fact that the first character cannot match the
last char of sgml-name-re.

lisp/arc-mode.el
lisp/erc/erc-dcc.el
lisp/net/puny.el
lisp/org/org-table.el
lisp/progmodes/gdb-mi.el
lisp/progmodes/scheme.el
lisp/textmodes/sgml-mode.el
lisp/vc/diff-mode.el

index 4d36667969048978b1c8d2b8110dee195a527cd8..c918f06c80e0ce61fec15a23b54d0d020dad47a7 100644 (file)
@@ -2032,7 +2032,7 @@ This doesn't recover lost files, it just undoes changes in the buffer itself."
           (call-process "lsar" nil t nil "-l" (or file copy))
         (if copy (delete-file copy)))
       (goto-char (point-min))
-      (re-search-forward "^\\(\s+=+\s*\\)+\n")
+      (re-search-forward "^\\(?:\s+=+\\)+\s*\n")
       (while (looking-at (concat "^\s+[0-9.]+\s+D?-+\s+"   ; Flags
                                  "\\([0-9-]+\\)\s+"        ; Size
                                  "\\([-0-9.]+\\)%?\s+"      ; Ratio
index 26701cec1e454bd7c26700d9354bebc07d66561e..8ccceec45945d9c41e11aefdeee786d45c2ec212 100644 (file)
@@ -627,11 +627,11 @@ that subcommand."
        ?q query ?n nick ?u login ?h host))))
 
 (defconst erc-dcc-ctcp-query-send-regexp
-  (concat "^DCC SEND \\("
+  (concat "^DCC SEND \\(?:"
           ;; Following part matches either filename without spaces
           ;; or filename enclosed in double quotes with any number
           ;; of escaped double quotes inside.
-          "\"\\(\\(.*?\\(\\\\\"\\)?\\)+?\\)\"\\|\\([^ ]+\\)"
+          "\"\\(\\(?:\\\\\"\\|[^\"\\]\\)+\\)\"\\|\\([^ ]+\\)"
           "\\) \\([0-9]+\\) \\([0-9]+\\) *\\([0-9]*\\)"))
 
 (define-inline erc-dcc-unquote-filename (filename)
@@ -653,11 +653,11 @@ It extracts the information about the dcc request and adds it to
        ?r "SEND" ?n nick ?u login ?h host))
      ((string-match erc-dcc-ctcp-query-send-regexp query)
       (let ((filename
-             (or (match-string 5 query)
-                 (erc-dcc-unquote-filename (match-string 2 query))))
-            (ip       (erc-decimal-to-ip (match-string 6 query)))
-            (port     (match-string 7 query))
-            (size     (match-string 8 query)))
+             (or (match-string 2 query)
+                 (erc-dcc-unquote-filename (match-string 1 query))))
+            (ip       (erc-decimal-to-ip (match-string 3 query)))
+            (port     (match-string 4 query))
+            (size     (match-string 5 query)))
         ;; FIXME: a warning really should also be sent
         ;; if the ip address != the host the dcc sender is on.
         (erc-display-message
index 60a6c12e6c732b4d4cf59dbaa0acbf7c470972d4..6987d253248d42af58893d72698efb52af0de08d 100644 (file)
@@ -35,7 +35,7 @@
 For instance, \"fśf.org\" => \"xn--ff-2sa.org\"."
   ;; The vast majority of domain names are not IDNA domain names, so
   ;; add a check first to avoid doing unnecessary work.
-  (if (string-match "\\'[[:ascii:]]+\\'" domain)
+  (if (string-match "\\`[[:ascii:]]+\\'" domain)
       domain
     (mapconcat 'puny-encode-string (split-string domain "[.]") ".")))
 
index 98702feb375356b6cc7af603355165bf431103fc..8927b1c2ed9140f7798a96b849abeb5980f1bd66 100644 (file)
@@ -2005,7 +2005,7 @@ the table and kill the editing buffer."
        text)
     (goto-char (point-min))
     (while (re-search-forward "^#.*\n?" nil t) (replace-match ""))
-    (while (re-search-forward "\\([ \t]*\n[ \t]*\\)+" nil t)
+    (while (re-search-forward "[ \t]*\\(?:\n[ \t]*\\)+" nil t)
       (replace-match " "))
     (setq text (org-trim (buffer-string)))
     (set-window-configuration cw)
index ba586981de6752056264c777f45b51126f89dd97..c1184211d0680543e6d82240435beda131b2d020 100644 (file)
@@ -1867,7 +1867,7 @@ static char *magick[] = {
    "\\|def\\(i\\(ne?\\)?\\)?\\|doc\\(u\\(m\\(e\\(nt?\\)?\\)?\\)?\\)?\\|"
    gdb-python-guile-commands-regexp
    "\\|while-stepping\\|stepp\\(i\\(ng?\\)?\\)?\\|ws\\|actions"
-   "\\|expl\\(o\\(r\\e?\\)?\\)?"
+   "\\|expl\\(o\\(re?\\)?\\)?"
    "\\)\\([[:blank:]]+\\([^[:blank:]]*\\)\\)*$")
   "Regexp matching GDB commands that enter a recursive reading loop.
 As long as GDB is in the recursive reading loop, it does not expect
index 751d7da5427ac41e77ae4882e2e25b06a3372e53..33ba0d11d8066a5f6d7f0479c9f9d5619609a7fd 100644 (file)
 
 (defvar scheme-imenu-generic-expression
       '((nil
-         "^(define\\(\\|-\\(generic\\(\\|-procedure\\)\\|method\\)\\)*\\s-+(?\\(\\sw+\\)" 4)
+         "^(define\\(?:-\\(?:generic\\(?:-procedure\\)?\\|method\\)\\)?\\s-+(?\\(\\sw+\\)" 1)
         ("Types"
          "^(define-class\\s-+(?\\(\\sw+\\)" 1)
         ("Macros"
index 6152a8ad0a791d095a129e4df8f8f978bf4da43a..9b29b844d01892f0425586c82c736e0f670e5b40 100644 (file)
@@ -286,7 +286,10 @@ separated by a space."
 (defconst sgml-namespace-re "[_[:alpha:]][-_.[:alnum:]]*")
 (defconst sgml-name-re "[_:[:alpha:]][-_.:[:alnum:]]*")
 (defconst sgml-tag-name-re (concat "<\\([!/?]?" sgml-name-re "\\)"))
-(defconst sgml-attrs-re "\\(?:[^\"'/><]\\|\"[^\"]*\"\\|'[^']*'\\)*")
+(defconst sgml-attrs-re
+  ;; This pattern cannot begin with a character matched by the end of
+  ;; `sgml-name-re' above.
+  "\\(?:[^_.:\"'/><[:alnum:]-]\\(?:[^\"'/><]\\|\"[^\"]*\"\\|'[^']*'\\)*\\)?")
 (defconst sgml-start-tag-regex (concat "<" sgml-name-re sgml-attrs-re)
   "Regular expression that matches a non-empty start tag.
 Any terminating `>' or `/' is not matched.")
index da2d5ed50e4f28fe34fa04ebdac1e376676427ec..d194d6c0a0e846eb9fb47926cc5855705a95ebcb 100644 (file)
@@ -484,7 +484,7 @@ and the face `diff-added' for added lines.")
   ;; Prefer second name as first is most likely to be a backup or
   ;; version-control name.  The [\t\n] at the end of the unidiff pattern
   ;; catches Debian source diff files (which lack the trailing date).
-  '((nil "\\+\\+\\+\\ \\([^\t\n]+\\)[\t\n]" 1) ; unidiffs
+  '((nil "\\+\\+\\+ \\([^\t\n]+\\)[\t\n]" 1) ; unidiffs
     (nil "^--- \\([^\t\n]+\\)\t.*\n\\*" 1))) ; context diffs
 
 ;;;;