{
	"description": "Test `Special:Ask` output on `mainlabel=.../?#...`, `format=table`",
	"setup": [
		{
			"namespace": "SMW_NS_PROPERTY",
			"page": "Has page extra",
			"contents": "[[Has type::Page]]"
		},
		{
			"page": "Example/SA0012/1",
			"contents": "[[Has page extra::123]] [[Category:SA0012]]"
		},
		{
			"page": "Example/SA0012/XSS",
			"contents": "[[Has page extra::Alpha]] [[Has page extra::Beta]] [[Category:SA0012XSS]]"
		}
	],
	"tests": [
		{
			"type": "special",
			"about": "#0 (?#, empty mainlabel)",
			"special-page": {
				"page": "Ask",
				"query-parameters": "-5B-5BCategory:SA0012-5D-5D/-3FHas-20page-20extra/-3F-23/mainlabel%3D/offset%3D0/format%3Dtable",
				"request-parameters": []
			},
			"assert-output": {
				"to-contain": [
					"<table class=\"sortable wikitable smwtable\">",
					"<a href=.*Property:Has_page_extra\" title=\"Property:Has page extra\">Has page extra</a></th><th>&nbsp;</th>",
					"<tr data-row-number=\"1\" class=\"row-odd\"><td class=\"Has-page-extra smwtype_wpg\" data-sort-value=\"123\">",
					"<td class=\"smwtype_wpg\"><a href=.*Example/SA0012/1\" title=\"Example/SA0012/1\">Example/SA0012/1</a></td>"
				]
			}
		},
		{
			"type": "special",
			"about": "#0.1 (?, empty mainlabel)",
			"special-page": {
				"page": "Ask",
				"query-parameters": "-5B-5BCategory:SA0012-5D-5D/-3FHas-20page-20extra/-3F/mainlabel%3D/offset%3D0/format%3Dtable",
				"request-parameters": []
			},
			"assert-output": {
				"to-contain": [
					"<table class=\"sortable wikitable smwtable\">",
					"<a href=.*Property:Has_page_extra\" title=\"Property:Has page extra\">Has page extra</a></th><th>&nbsp;</th>",
					"<tr data-row-number=\"1\" class=\"row-odd\"><td class=\"Has-page-extra smwtype_wpg\" data-sort-value=\"123\">",
					"<td class=\"smwtype_wpg\"><a href=.*Example/SA0012/1\" title=\"Example/SA0012/1\">Example/SA0012/1</a></td>"
				]
			}
		},
		{
			"type": "special",
			"about": "#1 (?#, mainlabel=-, output the same as in #0)",
			"special-page": {
				"page": "Ask",
				"query-parameters": "-5B-5BCategory:SA0012-5D-5D/-3FHas-20page-20extra/-3F-23/mainlabel%3D-2D/offset%3D0/format%3Dtable",
				"request-parameters": []
			},
			"assert-output": {
				"to-contain": [
					"<table class=\"sortable wikitable smwtable\">",
					"<a href=.*Property:Has_page_extra\" title=\"Property:Has page extra\">Has page extra</a></th><th>&nbsp;</th>",
					"<tr data-row-number=\"1\" class=\"row-odd\"><td class=\"Has-page-extra smwtype_wpg\" data-sort-value=\"123\">",
					"<td class=\"smwtype_wpg\"><a href=.*Example/SA0012/1\" title=\"Example/SA0012/1\">Example/SA0012/1</a></td>"
				]
			}
		},
		{
			"type": "special",
			"about": "#2 (?#, mainlabel=FOO, ?# takes precedence over mainlabel, same output as in #0)",
			"special-page": {
				"page": "Ask",
				"query-parameters": "-5B-5BCategory:SA0012-5D-5D/-3FHas-20page-20extra/-3F-23/mainlabel%3DFOO/offset%3D0/format%3Dtable",
				"request-parameters": []
			},
			"assert-output": {
				"to-contain": [
					"<table class=\"sortable wikitable smwtable\">",
					"<a href=.*Property:Has_page_extra\" title=\"Property:Has page extra\">Has page extra</a></th><th>&nbsp;</th>",
					"<tr data-row-number=\"1\" class=\"row-odd\"><td class=\"Has-page-extra smwtype_wpg\" data-sort-value=\"123\">",
					"<td class=\"smwtype_wpg\"><a href=.*Example/SA0012/1\" title=\"Example/SA0012/1\">Example/SA0012/1</a></td>"
				]
			}
		},
		{
			"type": "special",
			"about": "#3 (?#- forces plain output, empty mainlabel)",
			"special-page": {
				"page": "Ask",
				"query-parameters": "-5B-5BCategory:SA0012-5D-5D/-3FHas-20page-20extra/-3F-23-2D/mainlabel%3D/offset%3D0/format%3Dtable",
				"request-parameters": []
			},
			"assert-output": {
				"to-contain": [
					"<table class=\"sortable wikitable smwtable\">",
					"<a href=.*Property:Has_page_extra\" title=\"Property:Has page extra\">Has page extra</a></th><th>&nbsp;</th>",
					"<tr data-row-number=\"1\" class=\"row-odd\"><td class=\"Has-page-extra smwtype_wpg\" data-sort-value=\"123\">",
					"<td class=\"smwtype_wpg\">Example/SA0012/1</td>"
				]
			}
		},
		{
			"type": "special",
			"about": "#4 (?#=Foo, empty mainlabel)",
			"special-page": {
				"page": "Ask",
				"query-parameters": "-5B-5BCategory:SA0012-5D-5D/-3FHas-20page-20extra/-3F-23%3DFoo/mainlabel%3D/offset%3D0/format%3Dtable",
				"request-parameters": []
			},
			"assert-output": {
				"to-contain": [
					"<table class=\"sortable wikitable smwtable\">",
					"<a href=.*Property:Has_page_extra\" title=\"Property:Has page extra\">Has page extra</a></th><th class=\"Foo\">Foo</th>",
					"<tr data-row-number=\"1\" class=\"row-odd\"><td class=\"Has-page-extra smwtype_wpg\" data-sort-value=\"123\">",
					"<td class=\"Foo smwtype_wpg\"><a href=.*Example/SA0012/1\" title=\"Example/SA0012/1\">Example/SA0012/1</a></td>"
				]
			}
		},
		{
			"type": "special",
			"about": "#4.1 (?=Foo, empty mainlabel)",
			"special-page": {
				"page": "Ask",
				"query-parameters": "-5B-5BCategory:SA0012-5D-5D/-3FHas-20page-20extra/-3F%3DFoo/mainlabel%3D/offset%3D0/format%3Dtable",
				"request-parameters": []
			},
			"assert-output": {
				"to-contain": [
					"<table class=\"sortable wikitable smwtable\">",
					"<a href=.*Property:Has_page_extra\" title=\"Property:Has page extra\">Has page extra</a></th><th class=\"Foo\">Foo</th>",
					"<tr data-row-number=\"1\" class=\"row-odd\"><td class=\"Has-page-extra smwtype_wpg\" data-sort-value=\"123\">",
					"<td class=\"Foo smwtype_wpg\"><a href=.*Example/SA0012/1\" title=\"Example/SA0012/1\">Example/SA0012/1</a></td>"
				]
			}
		},
		{
			"type": "special",
			"about": "#5 (?#=Foo#- forces plain output, empty mainlabel)",
			"special-page": {
				"page": "Ask",
				"query-parameters": "-5B-5BCategory:SA0012-5D-5D/-3FHas-20page-20extra/-3F-23%3DFoo-23-2D/mainlabel%3D/offset%3D0/format%3Dtable",
				"request-parameters": []
			},
			"assert-output": {
				"to-contain": [
					"<table class=\"sortable wikitable smwtable\">",
					"<a href=.*Property:Has_page_extra\" title=\"Property:Has page extra\">Has page extra</a></th><th class=\"Foo\">Foo</th>",
					"<tr data-row-number=\"1\" class=\"row-odd\"><td class=\"Has-page-extra smwtype_wpg\" data-sort-value=\"123\">",
					"<td class=\"Foo smwtype_wpg\">Example/SA0012/1</td>"
				]
			}
		},
		{
			"type": "special",
			"about": "#6 (?#=Foo#- forces plain output, mainlabel=-, same output as in #5)",
			"special-page": {
				"page": "Ask",
				"query-parameters": "-5B-5BCategory:SA0012-5D-5D/-3FHas-20page-20extra/-3F-23%3DFoo-23-2D/mainlabel%3D-2D/offset%3D0/format%3Dtable",
				"request-parameters": []
			},
			"assert-output": {
				"to-contain": [
					"<table class=\"sortable wikitable smwtable\">",
					"<a href=.*Property:Has_page_extra\" title=\"Property:Has page extra\">Has page extra</a></th><th class=\"Foo\">Foo</th>",
					"<tr data-row-number=\"1\" class=\"row-odd\"><td class=\"Has-page-extra smwtype_wpg\" data-sort-value=\"123\">",
					"<td class=\"Foo smwtype_wpg\">Example/SA0012/1</td>"
				]
			}
		},
		{
			"type": "special",
			"about": "#7 (XSS payload in the sep parameter is escaped in HTML output)",
			"special-page": {
				"page": "Ask",
				"request-parameters": {
					"p": {
						"limit": "10",
						"offset": "0",
						"mainlabel": "-",
						"format": "table",
						"sep": "\"><x id=X tabindex=1 onfocus=a=0||alert,a(0||document.domain)>"
					},
					"q": "[[Category:SA0012XSS]]",
					"po": "?Has page extra"
				}
			},
			"assert-output": {
				"to-contain": [
					"&quot;&gt;&lt;x id=X tabindex=1 onfocus=a=0||alert,a(0||document.domain)&gt;"
				],
				"not-contain": [
					"<x id=X tabindex=1 onfocus=a=0||alert,a(0||document.domain)>"
				]
			}
		},
		{
			"type": "special",
			"about": "#8 (XSS payload in the sep parameter is escaped for request_type=raw output)",
			"special-page": {
				"page": "Ask",
				"request-parameters": {
					"p": {
						"limit": "10",
						"offset": "0",
						"mainlabel": "-",
						"format": "table",
						"sep": "\"><x id=X tabindex=1 onfocus=a=0||alert,a(0||document.domain)>"
					},
					"q": "[[Category:SA0012XSS]]",
					"po": "?Has page extra",
					"request_type": "raw"
				}
			},
			"assert-output": {
				"to-contain": [
					"&quot;&gt;&lt;x id=X tabindex=1 onfocus=a=0||alert,a(0||document.domain)&gt;"
				],
				"not-contain": [
					"<x id=X tabindex=1 onfocus=a=0||alert,a(0||document.domain)>"
				]
			}
		},
		{
			"type": "special",
			"about": "#9 (headers=plain, XSS payload in mainlabel is escaped)",
			"special-page": {
				"page": "Ask",
				"request-parameters": {
					"p": {
						"limit": "10",
						"offset": "0",
						"headers": "plain",
						"mainlabel": "<img src=x onerror=alert() >",
						"format": "table"
					},
					"q": "[[Category:SA0012]]",
					"po": "?Has page extra"
				}
			},
			"assert-output": {
				"to-contain": [
					"<table class=\"sortable wikitable smwtable\">",
					"<th.*>&lt;img src=x onerror=alert() &gt;</th>",
					"<th class=\"Has-page-extra\">Has page extra</th>"
				],
				"not-contain": [
					"<img src=x onerror=alert() >"
				]
			}
		},
		{
			"type": "special",
			"about": "#10 (headers=plain, XSS payload in a property label is escaped)",
			"special-page": {
				"page": "Ask",
				"request-parameters": {
					"p": {
						"limit": "10",
						"offset": "0",
						"headers": "plain",
						"mainlabel": "-",
						"format": "table"
					},
					"q": "[[Category:SA0012]]",
					"po": "?Has page extra=<img src=x onerror=alert() >"
				}
			},
			"assert-output": {
				"to-contain": [
					"<table class=\"sortable wikitable smwtable\">",
					"<th.*>&lt;img src=x onerror=alert() &gt;</th>"
				],
				"not-contain": [
					"<img src=x onerror=alert() >"
				]
			}
		}
	],
	"settings": {
		"wgContLang": "en",
		"wgLanguageCode": "en",
		"smwgPageSpecialProperties": [
			"_MDAT"
		],
		"smwgNamespacesWithSemanticLinks": {
			"NS_MAIN": true,
			"SMW_NS_PROPERTY": true
		}
	},
	"meta": {
		"version": "2",
		"is-incomplete": false,
		"debug": false
	}
}