Repository: nextcloud/desktop (C++)

Issue:
[Bug]: Public link detection matches any URL containing /s/
### ⚠️ Before submitting, please verify the following: ⚠️

- [x] This is a **bug**, not a question or a configuration issue.
- [x] This issue is **not** already reported on Github (I've searched it).
- [x] Nextcloud Server and Desktop Client are **up to date**. See [Server Maintenance and Release Schedule](https://github.com/nextcloud/server/wiki/Maintenance-and-Release-Schedule) and [Desktop Releases](https://nextcloud.com/install/#install-clients) for supported versions.
- [x] I agree to follow Nextcloud's [Code of Conduct](https://nextcloud.com/contribute/code-of-conduct/)

### Bug description

In Nextcloud Desktop 4.0, the client incorrectly identifies URLs as public share links if they contain `/s/` anywhere in the path. This happens because the regex used in `Account::setUrl` matches any occurrence of /s/, even when it is followed by additional path segments.

Relevant code: https://github.com/nextcloud/desktop/blob/b3cc44948989559be95359b5b876e8aa506601d3/src/libsync/account.cpp#L560

Currently the regex is:
`(((https|http)://[^/]*).*/s/([^/]*))`
Proposed change:
`(((https|http)://[^/]*).*/s/([^/]*)$)`


### Steps to reproduce

1. Create a Nextcloud Server available under a subpath: `https://example.com/s/nextcloud/`
2. Observe that you can't sync it in the desktop client, because the client assumes this is a share link.


### Expected behavior

Match `/s/<token>` only when there are no additional `/` characters after the token.

### Which files are affected by this bug

https://github.com/nextcloud/desktop/blob/stable-4.0/src/libsync/account.cpp#L560

### Operating system

Windows

### Which version of the operating system you are running.

Windows 11

### Package

Official Windows MSI

### Nextcloud Server version

doesn't matter

### Nextcloud Desktop Client version

4.0

### Is this bug present after an update or on a fresh install?

Updated to a major version (ex. 3.16.3 to 3.17.0)

### Are you using the Nextcloud Server Encryption module?

Encryption is Enabled

### Are you using an external user-backend?

- [ ] Default internal user-backend
- [ ] LDAP/ Active Directory
- [ ] SSO - SAML
- [ ] Other

### Nextcloud Server logs

```shell

```

### Additional info

_No response_


Discussion: thanks for the bug report!

I implemented your proposed change in #8932 and prepared a Windows build with it: https://cloud.nextcloud.com/s/S8eH9Bx69ebWdTw

Please give it a try and report back if that's working for you
Works now, thanks!
awesome, thanks for testing :D 

Does it keep working after a restart of the client?
Yes it does. However in the `nextcloud.cfg` file I originally had the url without the trailing `/`:
```
0\url=https://example.com/s/nextcloud
```
I added it yesterday while debugging why it has stopped working. The client seems not to override it so it is resolved for me, but there may be folks with config such as mine and they will still have this broken



Fix (patch):
diff --git a/src/libsync/account.cpp b/src/libsync/account.cpp
index 2c254a8685a9c..08530a00d7bc5 100644
--- a/src/libsync/account.cpp
+++ b/src/libsync/account.cpp
@@ -557,7 +557,7 @@ void Account::setSslErrorHandler(AbstractSslErrorHandler *handler)
 
 void Account::setUrl(const QUrl &url)
 {
-    const QRegularExpression discoverPublicLinks(R"(((https|http)://[^/]*).*/s/([^/]*))");
+    const QRegularExpression discoverPublicLinks(R"(((https|http)://[^/]*).*/s/([^/]*)$)");
     const auto isPublicLink = discoverPublicLinks.match(url.toString());
     if (isPublicLink.hasMatch()) {
         _url = QUrl::fromUserInput(isPublicLink.captured(1));