From c728448a4d05268d4febb9950a39d517a75ea052 Mon Sep 17 00:00:00 2001
From: toasted-nutbread
Date: Fri, 18 Dec 2020 11:24:43 -0500
Subject: Maximum clipboard search length (#1118)
* Add maximumClipboardSearchLength an option
* Add setting
* Add limits
* Update tests
---
ext/bg/data/options-schema.json | 8 +++++++-
ext/bg/js/backend.js | 4 ++++
ext/bg/js/options.js | 13 +++++++++++++
ext/bg/js/search.js | 4 ++++
ext/bg/settings2.html | 9 +++++++++
test/test-options-util.js | 5 +++--
6 files changed, 40 insertions(+), 3 deletions(-)
diff --git a/ext/bg/data/options-schema.json b/ext/bg/data/options-schema.json
index 4a953243..85275952 100644
--- a/ext/bg/data/options-schema.json
+++ b/ext/bg/data/options-schema.json
@@ -108,7 +108,8 @@
"showIframePopupsInRootFrame",
"useSecurePopupFrameUrl",
"usePopupShadowDom",
- "usePopupWindow"
+ "usePopupWindow",
+ "maximumClipboardSearchLength"
],
"properties": {
"enable": {
@@ -259,6 +260,11 @@
"usePopupWindow": {
"type": "boolean",
"default": false
+ },
+ "maximumClipboardSearchLength": {
+ "type": "integer",
+ "default": 1000,
+ "minimum": 0
}
}
},
diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js
index b731fc6c..fb11ba2e 100644
--- a/ext/bg/js/backend.js
+++ b/ext/bg/js/backend.js
@@ -240,6 +240,10 @@ class Backend {
// Event handlers
async _onClipboardTextChange({text}) {
+ const {general: {maximumClipboardSearchLength}} = this.getOptions({current: true});
+ if (text.length > maximumClipboardSearchLength) {
+ text = text.substring(0, maximumClipboardSearchLength);
+ }
try {
const {tab, created} = await this._getOrCreateSearchPopup();
await this._focusTab(tab);
diff --git a/ext/bg/js/options.js b/ext/bg/js/options.js
index 5fb10516..876079dc 100644
--- a/ext/bg/js/options.js
+++ b/ext/bg/js/options.js
@@ -481,6 +481,10 @@ class OptionsUtil {
{
async: true,
update: this._updateVersion6.bind(this)
+ },
+ {
+ async: false,
+ update: this._updateVersion7.bind(this)
}
];
}
@@ -654,4 +658,13 @@ class OptionsUtil {
templates = templates.replace(/\bcompactGlossaries=((?:\.*\/)*)compactGlossaries\b/g, (g0, g1) => `${g0} data=${g1}.`);
return templates;
}
+
+ _updateVersion7(options) {
+ // Version 7 changes:
+ // Added general.maximumClipboardSearchLength.
+ for (const profile of options.profiles) {
+ profile.options.general.maximumClipboardSearchLength = 1000;
+ }
+ return options;
+ }
}
diff --git a/ext/bg/js/search.js b/ext/bg/js/search.js
index d99e76e0..85efc7a0 100644
--- a/ext/bg/js/search.js
+++ b/ext/bg/js/search.js
@@ -197,6 +197,10 @@ class DisplaySearch extends Display {
}
_onExternalSearchUpdate({text, animate=true}) {
+ const {general: {maximumClipboardSearchLength}} = this.getOptions();
+ if (text.length > maximumClipboardSearchLength) {
+ text = text.substring(0, maximumClipboardSearchLength);
+ }
this._queryInput.value = text;
this._search(animate, false);
}
diff --git a/ext/bg/settings2.html b/ext/bg/settings2.html
index 7e2e2e35..8ff0f14e 100644
--- a/ext/bg/settings2.html
+++ b/ext/bg/settings2.html
@@ -399,6 +399,15 @@
+
+
+
Maximum clipboard text search length
+
Limit the number of text characters used when searching clipboard content.
+
+
+
+
+
diff --git a/test/test-options-util.js b/test/test-options-util.js
index cfb1c87d..ca14e8d4 100644
--- a/test/test-options-util.js
+++ b/test/test-options-util.js
@@ -292,7 +292,8 @@ function createProfileOptionsUpdatedTestData1() {
showIframePopupsInRootFrame: false,
useSecurePopupFrameUrl: true,
usePopupShadowDom: true,
- usePopupWindow: false
+ usePopupWindow: false,
+ maximumClipboardSearchLength: 1000
},
audio: {
enabled: true,
@@ -498,7 +499,7 @@ function createOptionsUpdatedTestData1() {
}
],
profileCurrent: 0,
- version: 6,
+ version: 7,
global: {
database: {
prefixWildcardsSupported: false
--
cgit v1.2.3