"""Offline Classic ASP AJAX + gethint.asp backend verification lab (IIS ASP & browser absent)."""
import html
import json
import urllib.parse
NAMES = [
"Anna", "Brittany", "Cinderella", "Diana", "Eva",
"Fiona", "Gunda", "Hege", "Inga", "Johanna",
"Kitty", "Linda", "Nina", "Ophelia", "Petunia",
"Amanda", "Raquel", "Cindy", "Doris", "Eve",
"Evita", "Sunniva", "Tove", "Unni", "Violet",
"Liza", "Elizabeth", "Ellen", "Wenche", "Vicky",
]
def gethint_asp(query_q: str) -> dict[str, object]:
"""Exact VBScript logic of gethint.asp: Response.Expires=-1 + UCase(Mid(a(i),1,Len(q)))."""
headers = {"Expires": "-1", "Cache-Control": "no-cache"}
q = query_q.upper()
hint = ""
if len(q) > 0:
for name in NAMES:
if q == name[:len(q)].upper():
hint = name if hint == "" else f"{hint} , {name}"
body = "no suggestion" if hint == "" else hint
return {"headers": headers, "body": body}
def show_hint_client_step(raw_input: str) -> dict[str, object]:
"""Models showHint(str) frontend branch & safe URL encoding / text escaping."""
if len(raw_input) == 0:
return {"requested": False, "url": "", "txtHint": ""}
url = "gethint.asp?q=" + urllib.parse.quote(raw_input, safe="")
resp = gethint_asp(raw_input)
safe_text = html.escape(str(resp["body"]))
return {"requested": True, "url": url, "txtHint": safe_text, "headers": resp["headers"]}
def main() -> None:
cases = []
# Case 1: Single and multiple prefix matches across 30-name array
expected1 = {
"array_size": 30,
"prefix_a": "Anna , Amanda",
"prefix_e": "Eva , Eve , Evita , Elizabeth , Ellen",
"prefix_ev": "Eva , Eve , Evita",
"prefix_vi": "Violet , Vicky",
}
actual1 = {
"array_size": len(NAMES),
"prefix_a": gethint_asp("a")["body"],
"prefix_e": gethint_asp("e")["body"],
"prefix_ev": gethint_asp("ev")["body"],
"prefix_vi": gethint_asp("vi")["body"],
}
cases.append({
"name": "gethint_prefix_match_single_and_multi",
"summary": "Verify 30-name array prefix matching with ' , ' separator matches gethint.asp logic.",
"expected": expected1,
"actual": actual1,
"passed": actual1 == expected1,
})
# Case 2: Case insensitivity, empty input client short-circuit, and no suggestion fallback
expected2 = {
"upper_anna": "Anna",
"lower_anna": "Anna",
"unmatched_zz": "no suggestion",
"direct_empty_server": "no suggestion",
"client_empty_requested": False,
"client_empty_txt": "",
}
client_empty = show_hint_client_step("")
actual2 = {
"upper_anna": gethint_asp("ANNA")["body"],
"lower_anna": gethint_asp("anna")["body"],
"unmatched_zz": gethint_asp("zz")["body"],
"direct_empty_server": gethint_asp("")["body"],
"client_empty_requested": client_empty["requested"],
"client_empty_txt": client_empty["txtHint"],
}
cases.append({
"name": "gethint_case_insensitive_and_empty",
"summary": "Verify UCase matching, 'no suggestion' fallback, and empty input client short-circuit.",
"expected": expected2,
"actual": actual2,
"passed": actual2 == expected2,
})
# Case 3: Response.Expires = -1 cache prevention & URL encoding of query parameter
c_res = show_hint_client_step("A&B")
expected3 = {
"expires_header": "-1",
"encoded_url": "gethint.asp?q=A%26B",
"txt_hint": "no suggestion",
}
actual3 = {
"expires_header": c_res["headers"]["Expires"],
"encoded_url": c_res["url"],
"txt_hint": c_res["txtHint"],
}
cases.append({
"name": "gethint_url_encoding_and_cache_header",
"summary": "Verify Response.Expires=-1 anti-cache header and proper URL encoding of special chars.",
"expected": expected3,
"actual": actual3,
"passed": actual3 == expected3,
})
# Case 4: XSS-safe output encoding check
xss_input = "<script>alert(1)</script>"
xss_step = show_hint_client_step(xss_input)
escaped_demo = html.escape("<img src=x onerror=alert(1)>")
expected4 = {
"xss_query_result": "no suggestion",
"escaped_contains_no_raw_tag": True,
}
actual4 = {
"xss_query_result": xss_step["txtHint"],
"escaped_contains_no_raw_tag": "<" not in escaped_demo and "<img" in escaped_demo,
}
cases.append({
"name": "gethint_xss_safe_output_encoding",
"summary": "Verify unsafe script input returns 'no suggestion' and HTML escaping blocks raw tags.",
"expected": expected4,
"actual": actual4,
"passed": actual4 == expected4,
})
print(json.dumps({
"version": "CPython 3.12.14 offline Classic ASP / VBScript verifier (IIS ASP absent)",
"cases": cases,
}, ensure_ascii=False, indent=2))
if __name__ == "__main__":
main()
本例需在 Windows x64、CPython 3.12.14、Playwright 与本地浏览器/标准库。 中运行,请复制源码、保存文件或下载工程包后在本地执行验证。
运行说明与环境独立工程
运行环境:Windows x64、CPython 3.12.14、Playwright 与本地浏览器/标准库。
入口文件:projects/asp-ajax-asp-lab/explore-ajax-asp.py
本地运行步骤快速上手
- 点击上方“保存源码”保存为
explore-ajax-asp.py,或下载右侧课程工程包。 - 确认本地已准备 Windows x64、CPython 3.12.14、Playwright 与本地浏览器/标准库。。
- 按对应章节命令执行,结合正文核对实际输出。
附件与关联工程包下载
课程关联工程包(登记关联36章) · 含当前章节或实例 · mbskycom202612a1425.zip
课程关联工程包(登记关联1章) · 含当前章节或实例 · mbskycom202612a1421.zip