diff options
| author | Mattias Engdegård | 2020-04-16 11:04:24 +0200 |
|---|---|---|
| committer | Mattias Engdegård | 2020-04-16 12:14:38 +0200 |
| commit | 905c0a13f7929298cb36151f46dbef03f7bdcbe4 (patch) | |
| tree | b2adb12f5e6810bf3784628efae69828bba3c464 | |
| parent | 01436fddfb2587271391e72b7eaa6c5c541b46d8 (diff) | |
| download | emacs-905c0a13f7929298cb36151f46dbef03f7bdcbe4.tar.gz emacs-905c0a13f7929298cb36151f46dbef03f7bdcbe4.zip | |
Fix bugs, inefficiencies and bad style in regexps
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.
| -rw-r--r-- | lisp/arc-mode.el | 2 | ||||
| -rw-r--r-- | lisp/erc/erc-dcc.el | 14 | ||||
| -rw-r--r-- | lisp/net/puny.el | 2 | ||||
| -rw-r--r-- | lisp/org/org-table.el | 2 | ||||
| -rw-r--r-- | lisp/progmodes/gdb-mi.el | 2 | ||||
| -rw-r--r-- | lisp/progmodes/scheme.el | 2 | ||||
| -rw-r--r-- | lisp/textmodes/sgml-mode.el | 5 | ||||
| -rw-r--r-- | lisp/vc/diff-mode.el | 2 |
8 files changed, 17 insertions, 14 deletions
diff --git a/lisp/arc-mode.el b/lisp/arc-mode.el index 4d366679690..c918f06c80e 100644 --- a/lisp/arc-mode.el +++ b/lisp/arc-mode.el | |||
| @@ -2032,7 +2032,7 @@ This doesn't recover lost files, it just undoes changes in the buffer itself." | |||
| 2032 | (call-process "lsar" nil t nil "-l" (or file copy)) | 2032 | (call-process "lsar" nil t nil "-l" (or file copy)) |
| 2033 | (if copy (delete-file copy))) | 2033 | (if copy (delete-file copy))) |
| 2034 | (goto-char (point-min)) | 2034 | (goto-char (point-min)) |
| 2035 | (re-search-forward "^\\(\s+=+\s*\\)+\n") | 2035 | (re-search-forward "^\\(?:\s+=+\\)+\s*\n") |
| 2036 | (while (looking-at (concat "^\s+[0-9.]+\s+D?-+\s+" ; Flags | 2036 | (while (looking-at (concat "^\s+[0-9.]+\s+D?-+\s+" ; Flags |
| 2037 | "\\([0-9-]+\\)\s+" ; Size | 2037 | "\\([0-9-]+\\)\s+" ; Size |
| 2038 | "\\([-0-9.]+\\)%?\s+" ; Ratio | 2038 | "\\([-0-9.]+\\)%?\s+" ; Ratio |
diff --git a/lisp/erc/erc-dcc.el b/lisp/erc/erc-dcc.el index 26701cec1e4..8ccceec4594 100644 --- a/lisp/erc/erc-dcc.el +++ b/lisp/erc/erc-dcc.el | |||
| @@ -627,11 +627,11 @@ that subcommand." | |||
| 627 | ?q query ?n nick ?u login ?h host)))) | 627 | ?q query ?n nick ?u login ?h host)))) |
| 628 | 628 | ||
| 629 | (defconst erc-dcc-ctcp-query-send-regexp | 629 | (defconst erc-dcc-ctcp-query-send-regexp |
| 630 | (concat "^DCC SEND \\(" | 630 | (concat "^DCC SEND \\(?:" |
| 631 | ;; Following part matches either filename without spaces | 631 | ;; Following part matches either filename without spaces |
| 632 | ;; or filename enclosed in double quotes with any number | 632 | ;; or filename enclosed in double quotes with any number |
| 633 | ;; of escaped double quotes inside. | 633 | ;; of escaped double quotes inside. |
| 634 | "\"\\(\\(.*?\\(\\\\\"\\)?\\)+?\\)\"\\|\\([^ ]+\\)" | 634 | "\"\\(\\(?:\\\\\"\\|[^\"\\]\\)+\\)\"\\|\\([^ ]+\\)" |
| 635 | "\\) \\([0-9]+\\) \\([0-9]+\\) *\\([0-9]*\\)")) | 635 | "\\) \\([0-9]+\\) \\([0-9]+\\) *\\([0-9]*\\)")) |
| 636 | 636 | ||
| 637 | (define-inline erc-dcc-unquote-filename (filename) | 637 | (define-inline erc-dcc-unquote-filename (filename) |
| @@ -653,11 +653,11 @@ It extracts the information about the dcc request and adds it to | |||
| 653 | ?r "SEND" ?n nick ?u login ?h host)) | 653 | ?r "SEND" ?n nick ?u login ?h host)) |
| 654 | ((string-match erc-dcc-ctcp-query-send-regexp query) | 654 | ((string-match erc-dcc-ctcp-query-send-regexp query) |
| 655 | (let ((filename | 655 | (let ((filename |
| 656 | (or (match-string 5 query) | 656 | (or (match-string 2 query) |
| 657 | (erc-dcc-unquote-filename (match-string 2 query)))) | 657 | (erc-dcc-unquote-filename (match-string 1 query)))) |
| 658 | (ip (erc-decimal-to-ip (match-string 6 query))) | 658 | (ip (erc-decimal-to-ip (match-string 3 query))) |
| 659 | (port (match-string 7 query)) | 659 | (port (match-string 4 query)) |
| 660 | (size (match-string 8 query))) | 660 | (size (match-string 5 query))) |
| 661 | ;; FIXME: a warning really should also be sent | 661 | ;; FIXME: a warning really should also be sent |
| 662 | ;; if the ip address != the host the dcc sender is on. | 662 | ;; if the ip address != the host the dcc sender is on. |
| 663 | (erc-display-message | 663 | (erc-display-message |
diff --git a/lisp/net/puny.el b/lisp/net/puny.el index 60a6c12e6c7..6987d253248 100644 --- a/lisp/net/puny.el +++ b/lisp/net/puny.el | |||
| @@ -35,7 +35,7 @@ | |||
| 35 | For instance, \"fśf.org\" => \"xn--ff-2sa.org\"." | 35 | For instance, \"fśf.org\" => \"xn--ff-2sa.org\"." |
| 36 | ;; The vast majority of domain names are not IDNA domain names, so | 36 | ;; The vast majority of domain names are not IDNA domain names, so |
| 37 | ;; add a check first to avoid doing unnecessary work. | 37 | ;; add a check first to avoid doing unnecessary work. |
| 38 | (if (string-match "\\'[[:ascii:]]+\\'" domain) | 38 | (if (string-match "\\`[[:ascii:]]+\\'" domain) |
| 39 | domain | 39 | domain |
| 40 | (mapconcat 'puny-encode-string (split-string domain "[.]") "."))) | 40 | (mapconcat 'puny-encode-string (split-string domain "[.]") "."))) |
| 41 | 41 | ||
diff --git a/lisp/org/org-table.el b/lisp/org/org-table.el index 98702feb375..8927b1c2ed9 100644 --- a/lisp/org/org-table.el +++ b/lisp/org/org-table.el | |||
| @@ -2005,7 +2005,7 @@ the table and kill the editing buffer." | |||
| 2005 | text) | 2005 | text) |
| 2006 | (goto-char (point-min)) | 2006 | (goto-char (point-min)) |
| 2007 | (while (re-search-forward "^#.*\n?" nil t) (replace-match "")) | 2007 | (while (re-search-forward "^#.*\n?" nil t) (replace-match "")) |
| 2008 | (while (re-search-forward "\\([ \t]*\n[ \t]*\\)+" nil t) | 2008 | (while (re-search-forward "[ \t]*\\(?:\n[ \t]*\\)+" nil t) |
| 2009 | (replace-match " ")) | 2009 | (replace-match " ")) |
| 2010 | (setq text (org-trim (buffer-string))) | 2010 | (setq text (org-trim (buffer-string))) |
| 2011 | (set-window-configuration cw) | 2011 | (set-window-configuration cw) |
diff --git a/lisp/progmodes/gdb-mi.el b/lisp/progmodes/gdb-mi.el index ba586981de6..c1184211d06 100644 --- a/lisp/progmodes/gdb-mi.el +++ b/lisp/progmodes/gdb-mi.el | |||
| @@ -1867,7 +1867,7 @@ static char *magick[] = { | |||
| 1867 | "\\|def\\(i\\(ne?\\)?\\)?\\|doc\\(u\\(m\\(e\\(nt?\\)?\\)?\\)?\\)?\\|" | 1867 | "\\|def\\(i\\(ne?\\)?\\)?\\|doc\\(u\\(m\\(e\\(nt?\\)?\\)?\\)?\\)?\\|" |
| 1868 | gdb-python-guile-commands-regexp | 1868 | gdb-python-guile-commands-regexp |
| 1869 | "\\|while-stepping\\|stepp\\(i\\(ng?\\)?\\)?\\|ws\\|actions" | 1869 | "\\|while-stepping\\|stepp\\(i\\(ng?\\)?\\)?\\|ws\\|actions" |
| 1870 | "\\|expl\\(o\\(r\\e?\\)?\\)?" | 1870 | "\\|expl\\(o\\(re?\\)?\\)?" |
| 1871 | "\\)\\([[:blank:]]+\\([^[:blank:]]*\\)\\)*$") | 1871 | "\\)\\([[:blank:]]+\\([^[:blank:]]*\\)\\)*$") |
| 1872 | "Regexp matching GDB commands that enter a recursive reading loop. | 1872 | "Regexp matching GDB commands that enter a recursive reading loop. |
| 1873 | As long as GDB is in the recursive reading loop, it does not expect | 1873 | As long as GDB is in the recursive reading loop, it does not expect |
diff --git a/lisp/progmodes/scheme.el b/lisp/progmodes/scheme.el index 751d7da5427..33ba0d11d80 100644 --- a/lisp/progmodes/scheme.el +++ b/lisp/progmodes/scheme.el | |||
| @@ -116,7 +116,7 @@ | |||
| 116 | 116 | ||
| 117 | (defvar scheme-imenu-generic-expression | 117 | (defvar scheme-imenu-generic-expression |
| 118 | '((nil | 118 | '((nil |
| 119 | "^(define\\(\\|-\\(generic\\(\\|-procedure\\)\\|method\\)\\)*\\s-+(?\\(\\sw+\\)" 4) | 119 | "^(define\\(?:-\\(?:generic\\(?:-procedure\\)?\\|method\\)\\)?\\s-+(?\\(\\sw+\\)" 1) |
| 120 | ("Types" | 120 | ("Types" |
| 121 | "^(define-class\\s-+(?\\(\\sw+\\)" 1) | 121 | "^(define-class\\s-+(?\\(\\sw+\\)" 1) |
| 122 | ("Macros" | 122 | ("Macros" |
diff --git a/lisp/textmodes/sgml-mode.el b/lisp/textmodes/sgml-mode.el index 6152a8ad0a7..9b29b844d01 100644 --- a/lisp/textmodes/sgml-mode.el +++ b/lisp/textmodes/sgml-mode.el | |||
| @@ -286,7 +286,10 @@ separated by a space." | |||
| 286 | (defconst sgml-namespace-re "[_[:alpha:]][-_.[:alnum:]]*") | 286 | (defconst sgml-namespace-re "[_[:alpha:]][-_.[:alnum:]]*") |
| 287 | (defconst sgml-name-re "[_:[:alpha:]][-_.:[:alnum:]]*") | 287 | (defconst sgml-name-re "[_:[:alpha:]][-_.:[:alnum:]]*") |
| 288 | (defconst sgml-tag-name-re (concat "<\\([!/?]?" sgml-name-re "\\)")) | 288 | (defconst sgml-tag-name-re (concat "<\\([!/?]?" sgml-name-re "\\)")) |
| 289 | (defconst sgml-attrs-re "\\(?:[^\"'/><]\\|\"[^\"]*\"\\|'[^']*'\\)*") | 289 | (defconst sgml-attrs-re |
| 290 | ;; This pattern cannot begin with a character matched by the end of | ||
| 291 | ;; `sgml-name-re' above. | ||
| 292 | "\\(?:[^_.:\"'/><[:alnum:]-]\\(?:[^\"'/><]\\|\"[^\"]*\"\\|'[^']*'\\)*\\)?") | ||
| 290 | (defconst sgml-start-tag-regex (concat "<" sgml-name-re sgml-attrs-re) | 293 | (defconst sgml-start-tag-regex (concat "<" sgml-name-re sgml-attrs-re) |
| 291 | "Regular expression that matches a non-empty start tag. | 294 | "Regular expression that matches a non-empty start tag. |
| 292 | Any terminating `>' or `/' is not matched.") | 295 | Any terminating `>' or `/' is not matched.") |
diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el index da2d5ed50e4..d194d6c0a0e 100644 --- a/lisp/vc/diff-mode.el +++ b/lisp/vc/diff-mode.el | |||
| @@ -484,7 +484,7 @@ and the face `diff-added' for added lines.") | |||
| 484 | ;; Prefer second name as first is most likely to be a backup or | 484 | ;; Prefer second name as first is most likely to be a backup or |
| 485 | ;; version-control name. The [\t\n] at the end of the unidiff pattern | 485 | ;; version-control name. The [\t\n] at the end of the unidiff pattern |
| 486 | ;; catches Debian source diff files (which lack the trailing date). | 486 | ;; catches Debian source diff files (which lack the trailing date). |
| 487 | '((nil "\\+\\+\\+\\ \\([^\t\n]+\\)[\t\n]" 1) ; unidiffs | 487 | '((nil "\\+\\+\\+ \\([^\t\n]+\\)[\t\n]" 1) ; unidiffs |
| 488 | (nil "^--- \\([^\t\n]+\\)\t.*\n\\*" 1))) ; context diffs | 488 | (nil "^--- \\([^\t\n]+\\)\t.*\n\\*" 1))) ; context diffs |
| 489 | 489 | ||
| 490 | ;;;; | 490 | ;;;; |