Bug 416509 - The searched text in "Google Selected Text" tool should be escaped
Summary: The searched text in "Google Selected Text" tool should be escaped
Status: RESOLVED FIXED
Alias: None
Product: kate
Classification: Applications
Component: general (show other bugs)
Version: 19.12.1
Platform: Arch Linux Linux
: NOR minor
Target Milestone: ---
Assignee: KWrite Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-01-20 21:30 UTC by Maciej Libera
Modified: 2020-01-21 18:07 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In: 20.04
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Maciej Libera 2020-01-20 21:30:00 UTC
SUMMARY
The searched text in external tool "Google Selected Text" is not escaped. If it contains meaningful, correct URL characters (like &, ?), they can be interpreted by browser as URL parts, not search query.

STEPS TO REPRODUCE
1. Highlight text with some special characters, e.g. 'something to search & something'
2. Use "Google Selected Text" tool
3. See browser address bar and google search field

OBSERVED RESULT
Address bar contains full searched text (in the same form in case of Firefox) but google search field contains only the part before '&', e.g. 'something to search'.

EXPECTED RESULT
Google search field contains whole text.

SOFTWARE/OS VERSIONS
Windows: 10, 19H1
Linux/KDE Plasma: Arch Linux
(available in About System)
KDE Plasma Version: 5.17.5
KDE Frameworks Version: 5.66.0
Qt Version: 5.14.0

ADDITIONAL INFORMATION
Thanks for the great editor :)
Comment 1 Dominik Haumann 2020-01-21 11:26:24 UTC
The problem here is that %{Document:Selection:Text} is simply the raw text, not escaped.

A solution to this could be to add another variable called: %{EscapeText:<value>}, we then could write:

https://www.google.com/search?q=%{EscapeText:%{Document:Selection:Text}}

Would 'EscapeText' be the best wording, or should we more closely follow the naming 'PercentEncoded' from QUrl, see: https://doc.qt.io/qt-5/qurl.html#toPercentEncoding
Comment 2 Christoph Cullmann 2020-01-21 11:36:39 UTC
If it does percent encoding, I think PercentEncoded makes the most sense.
Comment 3 Dominik Haumann 2020-01-21 17:33:53 UTC
Git commit b0055e8476bb5d9a48e317230ce8becc60cf78af by Dominik Haumann.
Committed on 21/01/2020 at 17:33.
Pushed by dhaumann into branch 'master'.

Variable expansion: Add variable PercentEncoded

Summary:
This can be used to encode the input text such that it can
be used in URIs. This is useful e.g. for the external tool
"Google Selected Text", where '&' and similar characters
are problematic in the url.

Test Plan: make && make test

Reviewers: cullmann

Reviewed By: cullmann

Subscribers: kwrite-devel, kde-frameworks-devel

Tags: #kate, #frameworks

Differential Revision: https://phabricator.kde.org/D26812

M  +4    -0    autotests/src/variable_test.cpp
M  +5    -0    src/utils/katevariableexpansionmanager.cpp

https://commits.kde.org/ktexteditor/b0055e8476bb5d9a48e317230ce8becc60cf78af
Comment 4 Dominik Haumann 2020-01-21 18:02:00 UTC
Git commit a07dceabbb02947f612bdee69da95e6bdb1de89a by Dominik Haumann.
Committed on 21/01/2020 at 18:01.
Pushed by dhaumann into branch 'external-tools-bug-416320'.

Fix External Tool "Google Selected Text"

...by using %{PercentEncoded:...} to make sure the
text is properly usable in the URI passed to the browser.

This will not be backported to 19.12, since the KTextEditor
framework only gained PercentEncoded in version 5.67.

FIXED-IN: 20.04

M  +1    -1    addons/externaltools/defaultexternaltoolsrc

https://invent.kde.org/kde/kate/commit/a07dceabbb02947f612bdee69da95e6bdb1de89a
Comment 5 Dominik Haumann 2020-01-21 18:02:03 UTC
Git commit a07dceabbb02947f612bdee69da95e6bdb1de89a by Dominik Haumann.
Committed on 21/01/2020 at 18:01.
Pushed by scmsync into branch 'external-tools-bug-416320'.

Fix External Tool "Google Selected Text"

...by using %{PercentEncoded:...} to make sure the
text is properly usable in the URI passed to the browser.

This will not be backported to 19.12, since the KTextEditor
framework only gained PercentEncoded in version 5.67.

FIXED-IN: 20.04

M  +1    -1    addons/externaltools/defaultexternaltoolsrc

https://commits.kde.org/kate/a07dceabbb02947f612bdee69da95e6bdb1de89a
Comment 6 Dominik Haumann 2020-01-21 18:07:12 UTC
Git commit d198c37cdb36f1d2f8f93610dcac4d26482e8bec by Dominik Haumann.
Committed on 21/01/2020 at 18:06.
Pushed by dhaumann into branch 'work-fix-bug-416509'.

Fix External Tool "Google Selected Text"

...by using %{PercentEncoded:...} to make sure the
text is properly usable in the URI passed to the browser.

This will not be backported to 19.12, since the KTextEditor
framework only gained PercentEncoded in version 5.67.

FIXED-IN: 20.04

M  +1    -1    addons/externaltools/defaultexternaltoolsrc

https://invent.kde.org/kde/kate/commit/d198c37cdb36f1d2f8f93610dcac4d26482e8bec
Comment 7 Dominik Haumann 2020-01-21 18:07:16 UTC
Git commit d198c37cdb36f1d2f8f93610dcac4d26482e8bec by Dominik Haumann.
Committed on 21/01/2020 at 18:06.
Pushed by scmsync into branch 'work-fix-bug-416509'.

Fix External Tool "Google Selected Text"

...by using %{PercentEncoded:...} to make sure the
text is properly usable in the URI passed to the browser.

This will not be backported to 19.12, since the KTextEditor
framework only gained PercentEncoded in version 5.67.

FIXED-IN: 20.04

M  +1    -1    addons/externaltools/defaultexternaltoolsrc

https://commits.kde.org/kate/d198c37cdb36f1d2f8f93610dcac4d26482e8bec