-- Self-check for panto-web. Run with: -- -- panto lua panto-web/_selfcheck.lua local registered = {} package.loaded["panto"] = { ext = { register_tool = function(tool) registered[#registered + 1] = tool end, json = { decode = function() return {} end, encode = function() return "{}" end, }, }, } local here = debug.getinfo(1, "S").source:match("^@(.*)/[^/]+$") or "." package.path = here .. "/panto-web/?.lua;" .. here .. "/panto-web/?/init.lua;" .. package.path local web = require("init") assert(web.name == "web", "entry name") local parsed = assert(web.parse_url("https://example.com:8443/docs?q=1")) assert(parsed.host == "example.com" and parsed.port == 8443, "URL host and port") local _, local_err = web.parse_url("http://user:pass@example.com/") assert(local_err:find("credentials", 1, true), "URL credentials rejected") assert(web.is_public_address("8.8.8.8"), "public IPv4 allowed") assert(not web.is_public_address("127.0.0.1"), "loopback IPv4 blocked") assert(not web.is_public_address("::1"), "loopback IPv6 blocked") assert(not web.is_public_address("::127.0.0.1"), "IPv4-compatible loopback blocked") local page, title = web.html_to_text([[
Hello <world>.
Read]]) assert(title == "A & B", "HTML title decoded") assert(page:find("Heading", 1, true) and page:find("Hello