From 35fea424eeb583ff0dee57e41026285d68e6f1d8 Mon Sep 17 00:00:00 2001 From: catborise Date: Sat, 10 Oct 2026 20:55:38 +0300 Subject: [PATCH] test: read the page scripts with lxml, not a tag regex CodeQL flags the ", page, re.S) if "pollWhileVisible(" in s) + script = next(s for s in html.fromstring(page).xpath("//script[not(@src)]/text()") if "pollWhileVisible(" in s) js = """ const vm = require("vm"); const charts = [], requests = []; diff --git a/instances/test_stats_sample.py b/instances/test_stats_sample.py index 98525870..ca83764a 100644 --- a/instances/test_stats_sample.py +++ b/instances/test_stats_sample.py @@ -3,7 +3,6 @@ its compute; the next poll sends it back so that the rates are averages since then, without waiting.""" import json -import re import shutil import subprocess import unittest @@ -15,6 +14,7 @@ from django.contrib.auth import get_user_model from django.core import signing from django.test import TestCase from django.urls import reverse +from lxml import html from instances.models import Instance from vrtManager.instance import USAGE_MAX_WINDOW @@ -140,7 +140,7 @@ class StatsScriptTestCase(TestDriverVM, TestCase): return response.content.decode() def test_the_next_poll_sends_the_previous_sample(self): - script = next(s for s in re.findall(r"", self.page(), re.S) if "statsSample" in s) + script = next(s for s in html.fromstring(self.page()).xpath("//script[not(@src)]/text()") if "statsSample" in s) js = """ const vm = require("vm"); const charts = [], requests = [], handlers = {};