diff --git a/moli-benchmark/moli_benchmark/wpt_cross/server.py b/moli-benchmark/moli_benchmark/wpt_cross/server.py index 5b48ccecbf..211252c909 100644 --- a/moli-benchmark/moli_benchmark/wpt_cross/server.py +++ b/moli-benchmark/moli_benchmark/wpt_cross/server.py @@ -1157,6 +1157,19 @@ def _xhr_inspect_headers_fixture_response( return headers, b"".join(parts) +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.""" @@ -2117,6 +2130,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 ce759332e6..5cc49feb67 100644 --- a/moli-benchmark/tests/test_wpt_cross.py +++ b/moli-benchmark/tests/test_wpt_cross.py @@ -139,6 +139,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, @@ -4072,6 +4073,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)