[Top][All Lists]
[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 11:31:43 +0600 |
Made a lot of mistakes here, apologies.
Guess my attention-span is even worse in the morning.
Few comments and corrected PATCH follows.
On Sun, 30 Oct 2011 10:50:20 +0600
Mike Kazantsev <address@hidden> wrote:
> 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"
>
Bad example with non-greedy +, it works only because later fields
match, correct one should be:
(let ((query "DCC SEND \"some \\\" 1 1 1 stuff with quotes\" 12345 123 123"))
(string-match
"^DCC SEND \\(\\([^ ]+\\)\\|\"\\(.*\\)\"\\) \\([0-9]+\\) \\([0-9]+\\)
*\\([0-9]*\\)"
query)
(map 'list (lambda (n) (match-string n query)) '(3 4 5 6)))
but I don't think it's really relevant.
> 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.
>
And I've managed to omit corrections to the group numbers there, which
is fixed in the version, attached here.
> 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?
>
Wrong, problem was the same group numbers which I've messed up, as
indicated above and actually fixed after needlessly modifying the
regexp.
From 970552d3e65b4d85d6602014c1d73d74693c7ed3 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..acbdbdf 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 \\("
+ ;; 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]*\\)"))
(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 6 query)))
+ (port (match-string 7 query))
+ (size (match-string 8 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
signature.asc
Description: PGP signature