Commit cf7bd900 authored by Lysander Trischler's avatar Lysander Trischler

Support comma as separator in single user clients

parent c17892fd
......@@ -28,7 +28,8 @@ Supported ``User-Agent`` Formats
* `Official single user client format
<https://twtxt.readthedocs.io/en/latest/user/discoverability.html>`_, e.g.
``twtxt/1.2.3 (+https://example.com/twtxt.txt; @somebody)``
``twtxt/1.2.3 (+https://example.com/twtxt.txt; @somebody)``, both semicolon
and comma are recognized separators
* `Extended multi user client format
<https://dev.twtxt.net/doc/useragentextension.html>`_, e.g.
......
......@@ -36,7 +36,7 @@ func ExtractUserAgentFromNginxAccessLog(line string) string {
const uri = `[\w:/._?&=@-]+`
var clientRegex = regexp.MustCompile(`(\w+)/([\w.@_/-]+)`)
var singleUserRegex = regexp.MustCompile(`\(\+(` + uri + `);\s*@(\w+)\)`)
var singleUserRegex = regexp.MustCompile(`\(\+(` + uri + `)[;,]\s*@(\w+)\)`)
var multiUserRegex = regexp.MustCompile(`\(~(` + uri + `)(;\s*contact=` + uri + `)?\)`)
var oldMultiUser25Regex = regexp.MustCompile(`\(Pod: ` + uri + ` Followers: ([\w\s]+) Support: (` + uri + `)\)`)
var oldMultiUser6Regex = regexp.MustCompile(`\(Pod: ` + uri + ` Followers: ([\w\s]+) and \d+ more... (` + uri + `) Support: ` + uri + `\)`)
......
......@@ -74,6 +74,17 @@ func TestParseUserAgent(t *testing.T) {
WhoFollowsURL: "",
},
},
{
name: "Single user client User-Agent with comma instead of semicolon as separator",
userAgent: "twtxt/1.1 (+http://twtxt.xyz/u/reednj.txt, @reednj) twtxt.xyz/1.21",
expected: UserAgent{
ClientName: "twtxt",
ClientVersion: "1.1",
TwtxtURLs: []string{"http://twtxt.xyz/u/reednj.txt"},
TwtxtNicks: []string{"reednj"},
WhoFollowsURL: "",
},
},
{
name: "Multi user client User-Agent with Who Follows Resource and contact information",
userAgent: "twtxt/0.1.0@35cbec4 (~https://twtxt.net/whoFollows?followers=9&token=3VFp9uq2B; contact=https://twtxt.net/support)",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment