erc-discuss
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Erc-discuss] [PATCH] erc-dcc: allow SEND commands containing quoted


From: Mike Kazantsev
Subject: Re: [Erc-discuss] [PATCH] erc-dcc: allow SEND commands containing quoted filenames with spaces in them
Date: Sun, 30 Oct 2011 10:50:20 +0600

On Sat, 29 Oct 2011 12:08:01 -0700
Michael Olson <address@hidden> wrote:

> Be careful with that regexp.  It's not going to be able to handle
> escaped quotes (with backslash, presumably).  I'd rather have it be
> flawless before checking in, unless it's IRC convention to not parse
> that kind of thing.  Also, <<.*+?>> is not very meaningful -- perhaps
> you meant <<.*?>> ?
> 

Indeed I didn't think about escaped quotes inside and .*+? is a
mistake, but second bug seem to cancel the first on out - since regexp
there is greedy, all the quotes inside should be matched:

(string-match
 "^DCC SEND \\(\\([^ ]+\\)\\|\"\\(.+?\\)\"\\) \\([0-9]+\\) \\([0-9]+\\) 
*\\([0-9]*\\)"
 "DCC SEND \"some \\\"stuff with quotes\" 12345 123 123")

Will produce following groups:

 "some \\\"stuff with quotes" "12345" "123" "123"

Which should be ok, unless quotes in the later fields should be
supported.
I've never seen these, but it's not hard to make a cleaner version,
which follows.

While testing it, I've stumbled upon another quirk which ERC (and this
regexp in particular) doesn't seem to support, which results in
"private" messages like this:

[10:20:12]-seekbot- DCC Send SearchBot_results_for_Rule 34.txt.zip (XX.XX.XX.XX)

Problem here is "Send" instead of "SEND", used by the IRC bot.
No specs I've been able to find mandate such usage, yet apparently it's
supported by xChat, at least.
It's trivial to make ERC support this one case (I've done it using
"(SEND|Send)" and incrementing the group numbers), and I can post it as
a separate patch, do you think it should be supported?


Fixed patch for quoted-filenames follows.

From 2139b47f9ba3bcd51e87985d7ed1e60fbe208aec Mon Sep 17 00:00:00 2001
From: Mike Kazantsev <address@hidden>
Date: Sat, 29 Oct 2011 11:36:49 +0600
Subject: [PATCH] erc-dcc: allow SEND commands containing quoted filenames
 with spaces in them

* erc-dcc.el (erc-dcc-ctcp-query-send-regexp): Updated regexp to match
    quoted filenames with spaces inside.
  (erc-dcc-handle-ctcp-send): Updated regexp match group numbers.
---
 erc-dcc.el |   16 +++++++++++-----
 1 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/erc-dcc.el b/erc-dcc.el
index 9e53edc..46b084b 100644
--- a/erc-dcc.el
+++ b/erc-dcc.el
@@ -646,7 +646,12 @@ that subcommand."
        ?q query ?n nick ?u login ?h host))))
 
 (defconst erc-dcc-ctcp-query-send-regexp
-  "^DCC SEND \\([^ ]+\\) \\([0-9]+\\) \\([0-9]+\\) *\\([0-9]*\\)")
+  (concat "^DCC SEND \\("
+    ;; Next 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]*\\)"))
 
 (defun erc-dcc-handle-ctcp-send (proc query nick login host to)
   "This is called if a CTCP DCC SEND subcommand is sent to the client.
@@ -661,10 +666,11 @@ It extracts the information about the dcc request and 
adds it to
        'dcc-request-bogus
        ?r "SEND" ?n nick ?u login ?h host))
      ((string-match erc-dcc-ctcp-query-send-regexp query)
-      (let ((filename (match-string 1 query))
-            (ip       (erc-decimal-to-ip (match-string 2 query)))
-            (port     (match-string 3 query))
-            (size     (match-string 4 query)))
+      (let ((filename
+              (or (match-string 2 query) (match-string 3 query)))
+            (ip       (erc-decimal-to-ip (match-string 4 query)))
+            (port     (match-string 5 query))
+            (size     (match-string 6 query)))
         ;; FIXME: a warning really should also be sent
         ;; if the ip address != the host the dcc sender is on.
         (erc-display-message
-- 
1.7.7


-- 
Mike Kazantsev // fraggod.net

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]