From 7297a18e0af7825e47a36ca009f67adaf827a71a Mon Sep 17 00:00:00 2001 From: mvolz Date: Mon, 24 Feb 2020 16:56:03 +0000 Subject: [PATCH] Update Zotero to f0cff95 Merge contains following changes: commit f0cff95617d1667c4c3855872d40483c1c069577 Author: Dan Stillman Date: Sun Feb 16 14:45:41 2020 -0500 Don't include `script` and `style` elements in innerText JSDOM doesn't support `innerText` [1], so our shim was just forwarding `textContent`. Instead, remove `script` and `style` elements, which won't do the same thing as in the browser but will hopefully remove most unwanted content. Addresses #111 [1] https://github.com/jsdom/jsdom/issues/1245 Bug: T245092 Change-Id: I5e24a0f1813960802e50c38f4b80f9bc0f23ef95 --- modules/translators | 2 +- package-lock.json | 2 +- package.json | 2 +- src/translation/translate.js | 8 +++++++- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/modules/translators b/modules/translators index 2901ba9..1b96abf 160000 --- a/modules/translators +++ b/modules/translators @@ -1 +1 @@ -Subproject commit 2901ba9fa5b4158cf87697a979a55ee7ad867fef +Subproject commit 1b96abf803535872be41ede811fc13be85b3dbe3 diff --git a/package-lock.json b/package-lock.json index f2f849e..14e2729 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "translation-server", - "version": "2.0.1", + "version": "2.0.3", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 1ecc793..747801a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "translation-server", - "version": "2.0.1", + "version": "2.0.3", "description": "Zotero translation server", "license": "AGPL-3.0-only", "main": "index.js", diff --git a/src/translation/translate.js b/src/translation/translate.js index f306886..e5bbbb3 100644 --- a/src/translation/translate.js +++ b/src/translation/translate.js @@ -63,7 +63,13 @@ Object.defineProperty(Attr.interface.prototype, 'innerText', { }); var Node = require('jsdom/lib/jsdom/living/generated/Node'); Object.defineProperty(Node.interface.prototype, 'innerText', { - get: function() { return this.textContent }, + get: function() { + // innerText in the browser is more sophisticated, but this removes most unwanted content + // https://github.com/jsdom/jsdom/issues/1245#issuecomment-584677454 + var el = this.cloneNode(true); + el.querySelectorAll('script,style').forEach(s => s.remove()) + return el.textContent + }, set: function(value) { this.textContent = value }, configurable: true, });