Commit Graph

16473 Commits

Author SHA1 Message Date
Ryan Roden-Corrent
102c6b99dd
Don't highlight html escapes in completion.
Resolves #4199.

To avoid accidentally highlighting characters that were introduced by
html escaping the text before feeding it to setHtml, we can't just
escape the whole string before adding the highlighting. Instead, we need
to break the string up on the pattern, format and escape the individual
parts, then join them back together.

re.escape includes empty strings if there is a match at the start/end,
which ensures that matches always land on odd indices:

https://docs.python.org/3/library/re.html#re.split

> If there are capturing groups in the separator and it matches at the
> start of the string, the result will start with an empty string. The
> same holds for the end of the string
2018-09-15 14:06:28 -04:00
Ryan Roden-Corrent
4f99af5876
Don't escape quotes in completion text.
Resolves the example case in #4199, but not the larger problem. We don't
need to escape quotes as we don't put the string in an attribute value.
From the docs at
https://docs.python.org/3/library/html.html#html.escape:

> If the optional flag quote is true, the characters (") and (') are also
> translated; this helps for inclusion in an HTML attribute value
> delimited by quotes, as in <a href="...">.

Escaping quotes means we end up with a literal &#x27; in the completion
view wherever there is a quote in the source text.

However, problem in #4199, where unexpected parts of the text are
highlighted, can also happen with '<', '>', and '&', which still must be
escaped.
2018-09-15 13:39:49 -04:00
Ryan Roden-Corrent
28c8e5682a
Unit test CompletionItemDelegate.paint.
There were no unit tests for this whole module. It is difficult to test
due to all the private logic and Qt dependencies, but with a lot of
mocking we can at least validate some of the text handling.

This is a setup to start testing the solution to #4199.

I picked '{' and '}' as placeholders in the test data because they draw
the eye to the 'highlighted' part, and vim even highlights them with
python syntax highlighting. It could be confusing though, as they look
like format strings but are not used that way.
2018-09-15 13:34:07 -04:00
Florian Bruhin
f9327731b8 Handle UTF-8 byte order marks in Greasemonkey scripts
See e.g. https://github.com/jerone/UserScripts/issues/135
2018-09-12 23:54:32 +02:00
Florian Bruhin
d0d73eec04 Regenerate docs 2018-09-12 16:07:25 +02:00
Florian Bruhin
91b8002dd5 Clean up workaround for sqlite opening errors
Now that we know the real cause, we can be a bit stricter with our workaround.
2018-09-12 16:06:57 +02:00
Jay Kamat
59af280f5c
Merge pull request #4206 from airodactyl/feature/support-multiple-words-tab-give-take
Support multiple words for :tab-take without quotes
2018-09-11 18:37:21 -07:00
Florian Bruhin
c2a072f9fe Fix handling of sqlite out of memory errors
The "error_code == -1" check never passed, as error_code (confusingly) is a
string of a number.
2018-09-12 01:36:50 +02:00
Florian Bruhin
c8b447daec Clean up raise_sqlite_error 2018-09-12 01:31:41 +02:00
Jay Kamat
d298d49f6f Update changelog 2018-09-11 15:26:38 -07:00
Florian Bruhin
941be6faed Add docstring 2018-09-11 20:45:15 +02:00
Florian Bruhin
6a480564cb Fix docs to say XDG_DATA_HOME instead of _DIR 2018-09-11 19:44:37 +02:00
Florian Bruhin
d80d9eb26c Allow downloading from PDF.js
When we click the download button in PDF.js, it downloads a blob://qute:...
URL. We can detect that and force a download rather than opening it in PDF.js
again.

Note that what actually happens depends on the Qt version and backend:

QtWebKit (any Qt version):
Downloads always work properly (regardless of Qt version).

QtWebEngine, Qt 5.7.1:
Downloads work.

QtWebEngine, Qt 5.9 - 5.11:
Downloads won't work as we need to tell PDF.js to not use blob: URLs:
https://bugreports.qt.io/browse/QTBUG-70420 - in theory, PDF.js could fall back
to downloading the existing qute:// URL, but it has a whitelist of schemes
which does not include qute://... Since it's not in that whitelist, it just
ends up doing nothing at all.

QtWebEngine, Qt 5.12:
Downloads should hopefully work properly again, as we can register the qute://
scheme with Chromium, which allows us to use blob:// URLs.
2018-09-10 13:15:39 +02:00
Florian Bruhin
02641b86fc Don't tell PDF.js to disable createObjectURL on Qt 5.7.1
Looks like things actually work fine there...
2018-09-10 13:01:01 +02:00
Florian Bruhin
3138c1f488 Update changelog 2018-09-10 11:58:27 +02:00
Florian Bruhin
bb96f8d297 Fix PDF.js test when no PDF.js is installed 2018-09-10 09:36:29 +02:00
Michael Hoang
1b618b2501 Set maxsplit to 0 on :tab-take 2018-09-10 10:03:58 +10:00
Florian Bruhin
9b04c4b8e0 Add missing tests for qute://pdfjs 2018-09-09 19:22:39 +02:00
Florian Bruhin
b4077a8543 Fix lint 2018-09-09 18:39:22 +02:00
Florian Bruhin
b96898db37 Simplify and lock down PDF.js filename handling 2018-09-09 18:35:09 +02:00
Florian Bruhin
231c1fbe59 Add underscore to temporary download filename suffix 2018-09-09 18:35:09 +02:00
Florian Bruhin
8cfa46f539 100% test coverage for browser.pdfjs 2018-09-09 18:35:09 +02:00
Florian Bruhin
f7169dc0ba Enable content.pdfjs setting on QtWebEngine 2018-09-09 18:35:09 +02:00
Florian Bruhin
36ad2c45b5 Clean up PDF.js snippet 2018-09-09 18:35:09 +02:00
Florian Bruhin
24babe76a1 Remove dead code
Thanks vulture!
2018-09-09 18:35:09 +02:00
Florian Bruhin
3e25262437 Remove old backend patching 2018-09-09 18:35:09 +02:00
Florian Bruhin
490fe5e1a3 Add utils.guess_mimetype 2018-09-09 18:35:09 +02:00
Florian Bruhin
24148c649e Fix lint and tests 2018-09-09 18:35:09 +02:00
Florian Bruhin
2dccde8f4b Only set PDFJS.disableCreateObjectURL when necessary
See #4198
2018-09-09 18:35:09 +02:00
Florian Bruhin
6665a1348e Use jinja to get PDF.js script 2018-09-09 18:35:09 +02:00
Florian Bruhin
3ad7ae2a2c Remove fix_urls which isn't needed anymore
With qute://pdfjs/web/viewer.html we can use relative URLs
2018-09-09 18:35:09 +02:00
Florian Bruhin
c40ddf37b7 Set disableCreateObjectURL for PDF.js
We can't use blob URLs or we'll get a renderer crash:
https://bugreports.qt.io/browse/QTBUG-70420

Thankfully, we can tell PDF.js to use data: URLs instead.
2018-09-09 18:35:09 +02:00
Florian Bruhin
bbcb87e434 Get PDF.js to work
We need to use the /web/viewer.html path so relative references are correct.
2018-09-09 18:35:09 +02:00
Florian Bruhin
7206dde19c Revert "Simplify getting pdfjs main page"
This reverts commit 9c731bde85627308fdde4730b0181a014096cb47.

We need to set some PDF.js options, so we can't just use the default viewer
with ?file=...
2018-09-09 18:35:09 +02:00
Florian Bruhin
a0b4f09f02 Initial PDF.js support for QtWebEngine 2018-09-09 18:35:09 +02:00
Florian Bruhin
cb0c313404 Add qute://pdfjs/file to get files
Cross-origin requests aren't supported for qute:// URLs, and qute:// can't
access file://, so we need to get the files that way.
2018-09-09 18:35:09 +02:00
Florian Bruhin
8f19820a7a Remove pdfjs.fix_urls
Now that we use qute://pdfjs to show the viewer, we don't need to rewrite any
URLs.
2018-09-09 18:35:09 +02:00
Florian Bruhin
24fb3b0d1b Simplify getting pdfjs main page 2018-09-09 18:35:09 +02:00
Florian Bruhin
df67c254f8 Initial attempt at getting PDF.js to work with separate downloads 2018-09-09 18:35:09 +02:00
Florian Bruhin
8f1690eff7 Move pdfjs error page to pdfjs.py 2018-09-09 18:35:09 +02:00
Florian Bruhin
36b2f5e63f Remove qute:// backend= argument 2018-09-09 18:35:09 +02:00
Florian Bruhin
dc82ac3eb2 Move qute_pdfjs to qutescheme.py 2018-09-09 18:35:09 +02:00
Florian Bruhin
b611ff52cf Support URL patterns for content.autoplay 2018-09-09 18:31:41 +02:00
Florian Bruhin
93eb05598e Fix request logging 2018-09-07 16:12:40 +02:00
Florian Bruhin
0b27779c9d Allow null initiator for qute:// URLs on Qt 5.11
Before Qt 5.11.2, for unique origins, we always got QUrl() and thus passed it
through.

With Qt 5.11.2, only missing origins (browser-initiated requests) get an empty
initiator, while unique origins get QUrl("null"):
https://codereview.qt-project.org/#/c/234849/
https://bugreports.qt.io/browse/QTBUG-69372

In theory, those should be locked down (as an unique origin is e.g. a sandboxed
iframe) and never have access to any other content.

However, thanks to a Qt bug, XHR on qute:// pages has QUrl("null") as origin as
long as the URL scheme is not registered. We can only do the registering once
Qt 5.12 is out.

Since unique origins were effectively already allowed on Qt 5.11.0/.1, we pass
them through here as well until Qt 5.12.

See #4198
2018-09-07 12:25:07 +02:00
Florian Bruhin
15c547b3f5 Move QuteSchemeHandler._check_initiator to its own method 2018-09-07 12:24:54 +02:00
Florian Bruhin
5ca911bcdb Fix lint 2018-09-06 20:09:57 +02:00
Florian Bruhin
4ca8fc0cb7 Use a shared web_history fixture 2018-09-06 20:08:32 +02:00
Florian Bruhin
ab6c8dde9a Decrease minimum QProgressDialog duration
We already have a threshold before we use a QProgressDialog at all, so let's
show it quite quickly and not after 4 seconds.
2018-09-06 17:26:28 +02:00
Florian Bruhin
935d93d10e Add tests for HistoryProgress 2018-09-06 17:26:28 +02:00