Subject: Re: bug#67600: [PATCH] Add dashes to 'thing-at-point-email-regexp'

From: Visuwesh <[email-masked]>
Date: Tue, 12 Dec 2023 18:53:25 +0530

[Tuesday December 12, 2023] Eli Zaretskii wrote:

>> From: Visuwesh <[email-masked]>
>> Cc: [email-masked],  [email-masked]
>> Date: Tue, 12 Dec 2023 18:11:47 +0530
>> 
>> [Tuesday December 12, 2023] Eli Zaretskii wrote:
>> 
>> >> I am running Emacs with the same change before Philip created this bug
>> >> report and so far I haven't had false positives for email addresses
>> >> because files with a @ in its name is rare.  In practise, I think this
>> >> patch is harmless in that regard.
>> >
>> > Remote files that have user@host in their names do have that
>> > character.
>> 
>> AFAIU, user cannot have slashes in them as per the POSIX standards [1]
>> and likewise with hostname so remote files should not pose a problem.
>> Of course this assumes that you're only looking at methods like ssh,
>> doas, sudo, etc.  It seems like tramp disallows slashes in user and host
>> anyway, try:
>> 
>>     (file-remote-p "/ssh:userwith/@host:/") ;; => nil
>>     (file-remote-p "/ssh:userwith@host/:/") ;; => nil
>>     (file-remote-p "/ssh:userwith@host:/") ;; => /ssh:userwith@host:
>
> Why are you talking about slashes in user and host names?  There are
> slashes in remote file names outside of those two.  Are you saying
> that slashes in thing-at-point-email-regexp will only ever match if
> they are in the user or host names?  That's not what I see:
>
>   (string-match "<?[-+_~a-zA-Z0-9/][-+_.~:a-zA-Z0-9/]*@[-a-zA-Z0-9]+[-.a-zA-Z0-9]*>?" 
>     "/ssh:userwith@host:/what/ever/it/can/be")
>       => 0

I see what you mean now.  But the problem is that even without the
slashes in the regexp, the filename you gave matches:

   (string-match "<?[-+_~a-zA-Z0-9][-+_.~:a-zA-Z0-9]*@[-a-zA-Z0-9]+[-.a-zA-Z0-9]*>?" 
     "/ssh:userwith@host:/what/ever/it/can/be") ;; => 1

the matched string is ssh:userwith@host.  So the old regexp will still
return false positives when the point is on userwith@host I think.

With the slashes, the matched string is /ssh:userwith@host.  If we drop
the slash from the first character class i.e.,

   (string-match "<?[-+_~a-zA-Z0-9][-+_.~:a-zA-Z0-9/]*@[-a-zA-Z0-9]+[-.a-zA-Z0-9]*>?" 
     "/ssh:userwith@host:/what/ever/it/can/be") ;; => 1

then the matched string is again ssh:userwith@host.  And this regexp
still matches the sr.ht list email addresses (this is the regexp I use
in my Emacs checkout).