https://bugs.kde.org/show_bug.cgi?id=510371

--- Comment #1 from ShwStone <[email protected]> ---
I am sure this is caused by a behavior of QUrl::fromUserInput

When opening a remote file via the `vscode-remote` protocol, `xdg-open`
receives a URL similar to this:
`vscode-remote://ssh+devserver/my/file/path`
(Where `ssh+` is an integral part of the scheme identifier.)

As I know, kde-open uses QUrl::fromUserInput to convert the input string into a
QUrl object. It then uses the resulting scheme to look up a registered
x-scheme-handler and select the appropriate application.

When the input string's scheme contains a plus sign (+), QUrl::fromUserInput
automatically prepends "http://"; to the link. This forces the URL to be
interpreted under the `http` protocol, which prevents `kde-open` from finding
the correct program and ultimately causes a browser to be launched.

My analysis of the documentation and source code suggests that URLs containing
a `+` sign (or its escape, `%2B`) are considered "invalid" by Qt's initial
parsing logic, triggering `QUrl::fromUserInput`'s "best guess" mechanism,
incorrectly defaults to prepending `http://`.

I've tried ask in QT forum, one of QT developer thinks this is not a QT
problem. But it is clear that either KDE or QT should make a change.(since this
is a basic function and gio open handles it perfectly).

If a change cannot be made at the Qt level, should KDE reconsider using
`QUrl::fromUserInput` for accepting general URL input in utilities like
`kde-open`?

I am not affiliated with the KDE or Qt development teams, but I am keen to
contribute to the resolution of this bug. I'm seeking insight into the
underlying standards and the most appropriate path forward.

BTW, following code can easily verify the core problem:

> #include <QString>
> #include <QUrl>
> #include <QDebug>
> int main() {
>    auto url = QUrl::fromUserInput("vscode-remote://ssh+devserver"); 
>    qDebug() << url; // QUrl("http://vscode-remote//ssh+devserver";)
>
>    url.setUrl("vscode-remote://ssh+devserver");
>    qDebug() << url.isValid(); // false
>
>    url.setUrl("vscode-remote://sshdevserver");
>    qDebug() << url.isValid(); // true
>
>    url.setUrl("vscode-remote://ssh%2Bdevserver");
>    qDebug() << url.isValid(); // false
>    return 0;
>}

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to