From 465ff6ee4494a96201ad01f5e53acf08f72a465a Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Mon, 13 Nov 2023 17:35:29 +0100 Subject: [PATCH] Misc fixes --- changedetectionio/forms.py | 2 +- changedetectionio/res/xpath_element_scraper.js | 12 ++++++++---- changedetectionio/tests/test_extract_regex.py | 3 --- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/changedetectionio/forms.py b/changedetectionio/forms.py index c640b218f..d86463053 100644 --- a/changedetectionio/forms.py +++ b/changedetectionio/forms.py @@ -351,7 +351,7 @@ class ValidateCSSJSONXPATHInput(object): raise ValidationError("XPath not permitted in this field!") from lxml import etree, html tree = html.fromstring("") - line = line.replace('xpath1:', '') + line = re.sub(r'^xpath1:', '', line) try: tree.xpath(line.strip()) diff --git a/changedetectionio/res/xpath_element_scraper.js b/changedetectionio/res/xpath_element_scraper.js index db927ed62..aac27f49f 100644 --- a/changedetectionio/res/xpath_element_scraper.js +++ b/changedetectionio/res/xpath_element_scraper.js @@ -170,9 +170,12 @@ if (include_filters.length) { try { // is it xpath? - if (f.startsWith('/') || f.startsWith('xpath:')) { - q = document.evaluate(f.replace('xpath:', ''), document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; + if (f.startsWith('/') || f.startsWith('xpath')) { + var qry_f = f.replace(/xpath(:|\d:)/, '') + console.log("[xpath] Scanning for included filter " + qry_f) + q = document.evaluate(qry_f, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; } else { + console.log("[css] Scanning for included filter " + f) q = document.querySelector(f); } } catch (e) { @@ -183,7 +186,7 @@ if (include_filters.length) { if (q) { // #1231 - IN the case XPath attribute filter is applied, we will have to traverse up and find the element. - if (q.hasOwnProperty('getBoundingClientRect')) { + if (typeof q.getBoundingClientRect == 'function') { bbox = q.getBoundingClientRect(); console.log("xpath_element_scraper: Got filter element, scroll from top was " + scroll_y) } else { @@ -192,7 +195,8 @@ if (include_filters.length) { bbox = q.ownerElement.getBoundingClientRect(); console.log("xpath_element_scraper: Got filter by ownerElement element, scroll from top was " + scroll_y) } catch (e) { - console.log("xpath_element_scraper: error looking up ownerElement") + console.log(e) + console.log("xpath_element_scraper: error looking up q.ownerElement") } } } diff --git a/changedetectionio/tests/test_extract_regex.py b/changedetectionio/tests/test_extract_regex.py index 7ff8f3a73..45a84800d 100644 --- a/changedetectionio/tests/test_extract_regex.py +++ b/changedetectionio/tests/test_extract_regex.py @@ -227,9 +227,6 @@ def test_regex_error_handling(client, live_server): follow_redirects=True ) - with open('/tmp/fuck.html', 'wb') as f: - f.write(res.data) - assert b'is not a valid regular expression.' in res.data res = client.get(url_for("form_delete", uuid="all"), follow_redirects=True)