diff --git a/moli-benchmark/moli_benchmark/wpt_cross/server.py b/moli-benchmark/moli_benchmark/wpt_cross/server.py index 4ffa6a0dbc..c57c7122df 100644 --- a/moli-benchmark/moli_benchmark/wpt_cross/server.py +++ b/moli-benchmark/moli_benchmark/wpt_cross/server.py @@ -1068,6 +1068,19 @@ def _wpt_delay_seconds(query: str) -> float | None: return delay_ms / 1_000.0 +def _workers_url_encoding_response(query: str) -> bytes: + """Model workers/semantics/encodings/003-1.py's UTF-8 query check.""" + value = next( + ( + value + for name, value in parse_qsl(query, keep_blank_values=True) + if name == "x" + ), + None, + ) + return b"PASS" if value == "å" else b"FAIL" + + def _redirect_fixture_response(query: str) -> tuple[int, str] | None: """Return the shared redirect response used by static WPT fixture handlers.""" @@ -1871,6 +1884,13 @@ def _make_handler( if path == "/xhr/resources/delay.py": self._serve_xhr_delay(parsed.query, emit_body=emit_body) return + if path == "/workers/semantics/encodings/003-1.py": + self._send_bytes( + "text/plain; charset=utf-8", + _workers_url_encoding_response(parsed.query), + emit_body=emit_body, + ) + return if path == ( "/html/semantics/scripting-1/the-script-element/module/" "resources/delayed-modulescript.py" diff --git a/moli-benchmark/tests/test_wpt_cross.py b/moli-benchmark/tests/test_wpt_cross.py index c7837631a0..a7248d63b5 100644 --- a/moli-benchmark/tests/test_wpt_cross.py +++ b/moli-benchmark/tests/test_wpt_cross.py @@ -140,6 +140,7 @@ from moli_benchmark.wpt_cross.server import ( _substitute_wpt_template_variables, _window_js_window_wrapper, _wasm_webapi_status_code, + _workers_url_encoding_response, _wpt_delay_seconds, _wpt_dedicated_worker_js_wrapper_html, _wpt_any_dedicated_worker_wrapper_html, @@ -4073,6 +4074,44 @@ test(() => {}, "ok"); self.assertIsNone(_wpt_delay_seconds("ms=-1")) self.assertIsNone(_wpt_delay_seconds("ms=nan")) + def test_fixture_server_models_worker_url_utf8_query_check(self) -> None: + self.assertEqual(_workers_url_encoding_response("x=%C3%A5"), b"PASS") + self.assertEqual(_workers_url_encoding_response("x=%C3%A5&x=wrong"), b"PASS") + self.assertEqual(_workers_url_encoding_response("x=%C3%83%C2%A5"), b"FAIL") + self.assertEqual(_workers_url_encoding_response("x=%E5"), b"FAIL") + self.assertEqual(_workers_url_encoding_response(""), b"FAIL") + + with tempfile.TemporaryDirectory() as root: + root_path = Path(root) + (root_path / "resources").mkdir() + (root_path / "resources" / "testharness.js").write_text( + "// testharness", encoding="utf-8" + ) + with WptFixtureServer(root_path) as server: + url = ( + f"{server.base_url}/workers/semantics/encodings/" + "003-1.py?x=%C3%A5" + ) + responses = [] + for method in ("GET", "HEAD"): + with urlopen(Request(url, method=method), timeout=2) as response: + responses.append( + ( + method, + response.status, + response.read(), + response.headers["Content-Type"], + ) + ) + + self.assertEqual( + responses, + [ + ("GET", 200, b"PASS", "text/plain; charset=utf-8"), + ("HEAD", 200, b"", "text/plain; charset=utf-8"), + ], + ) + def test_fixture_server_models_xhr_delay_py_methods(self) -> None: with tempfile.TemporaryDirectory() as root: root_path = Path(root)