| 1 | import hashlib |
| 2 | from pathlib import Path |
| 3 | |
| 4 | examples = [ |
| 5 | "", |
| 6 | "\n", |
| 7 | " ", |
| 8 | "#", |
| 9 | "#\x00", |
| 10 | "#?%2F", |
| 11 | "#Animal", |
| 12 | "#bar", |
| 13 | "#ccc", |
| 14 | "#here", |
| 15 | "#s", |
| 16 | "#\ue000", |
| 17 | "%", |
| 18 | "%2F", |
| 19 | "%AZ", |
| 20 | "%ZZ", |
| 21 | ".", |
| 22 | "..", |
| 23 | "../", |
| 24 | "../..", |
| 25 | "../../", |
| 26 | "../../../../g", |
| 27 | "../../../g", |
| 28 | "../../d", |
| 29 | "../../g", |
| 30 | "../../x%2Fabc", |
| 31 | "../abc", |
| 32 | "../b/c", |
| 33 | "../g", |
| 34 | "../r", |
| 35 | "../x%2Fabc", |
| 36 | "..g", |
| 37 | "./", |
| 38 | "./#", |
| 39 | "./#blort", |
| 40 | "./../g", |
| 41 | "./g", |
| 42 | "./g/.", |
| 43 | "./p=q:r", |
| 44 | "./q:r", |
| 45 | ".foo", |
| 46 | ".g", |
| 47 | "/", |
| 48 | "/\x00", |
| 49 | "/.", |
| 50 | "/../g", |
| 51 | "/./g", |
| 52 | "/.foo", |
| 53 | "//", |
| 54 | "///g", |
| 55 | "///lv2.h", |
| 56 | "//[2010:836B:4179::836B:4179]", |
| 57 | "//example.org/aaa/bbb#ccc", |
| 58 | "//g", |
| 59 | "//g/x", |
| 60 | "//͏@[]", |
| 61 | "//\uffff", |
| 62 | "/a/b/c/./../../g", |
| 63 | "/aaa/bbb#ccc", |
| 64 | "/cgi-bin/query?query=hello#fragment", |
| 65 | "/demo.txt", |
| 66 | "/example/x/abc", |
| 67 | "/g", |
| 68 | "/hello/demo.txt", |
| 69 | "/lv2.h", |
| 70 | "/r", |
| 71 | "/x%2Fabc", |
| 72 | "/x/y?q", |
| 73 | "/\ue000", |
| 74 | "/\uf8ff", |
| 75 | "/\ufdef", |
| 76 | "/\uffff", |
| 77 | ":a/b", |
| 78 | ";x", |
| 79 | "?\x00", |
| 80 | "?%2F", |
| 81 | "?bar", |
| 82 | "?pp/rr", |
| 83 | "?y", |
| 84 | "?\ue000", |
| 85 | "?\ufdef", |
| 86 | "?\uffff", |
| 87 | "A C", |
| 88 | "A%Z", |
| 89 | "A'C", |
| 90 | "A<C", |
| 91 | "A>C", |
| 92 | "A[**]C", |
| 93 | "A[C", |
| 94 | "A\\C", |
| 95 | "A]C", |
| 96 | "A^C", |
| 97 | "A`C", |
| 98 | "A{C", |
| 99 | "A|C", |
| 100 | "A}C", |
| 101 | "HTTP://EXAMPLE.ORG/AAA/BBB#CCC", |
| 102 | "[2010:836B:4179::836B:4179]", |
| 103 | "aaa%2Fbbb", |
| 104 | "abc", |
| 105 | "about:", |
| 106 | "bar:abc", |
| 107 | "bbb#ccc", |
| 108 | "beepbeep\x07\x07", |
| 109 | "dav:", |
| 110 | "demo.txt", |
| 111 | "demo/hello.txt", |
| 112 | "demo/hello.txt?query=hello#fragment", |
| 113 | "file:///C:/DEV/Haskell/lib/HXmlToolbox-3.01/examples/", |
| 114 | "file:///foo/bar", |
| 115 | "file://foo", |
| 116 | "file://meetings.example.com/cal#m1", |
| 117 | "ftp://ex/x/q/r", |
| 118 | "ftp://ftp.is.co.za/rfc/rfc1808.txt", |
| 119 | "ftp://www.yahoo.com/", |
| 120 | "ftp://www.yahoo.com/hello", |
| 121 | "g", |
| 122 | "g#s", |
| 123 | "g#s/../x", |
| 124 | "g#s/./x", |
| 125 | "g.", |
| 126 | "g..", |
| 127 | "g/", |
| 128 | "g/../h", |
| 129 | "g/./h", |
| 130 | "g:h", |
| 131 | "g;x", |
| 132 | "g;x=1/../y", |
| 133 | "g;x=1/./y", |
| 134 | "g;x?y#s", |
| 135 | "g?y", |
| 136 | "g?y#s", |
| 137 | "g?y/../x", |
| 138 | "g?y/./x", |
| 139 | "hello/demo.txt", |
| 140 | "htt:/", |
| 141 | "htt:/foo/", |
| 142 | "htt:/foo/gp", |
| 143 | "htt:/gp", |
| 144 | "http:", |
| 145 | "http:.", |
| 146 | "http://", |
| 147 | "http://1.2.3.4/", |
| 148 | "http://[/", |
| 149 | "http://[1080:0:0:0:8:800:200C:417A]/index.html", |
| 150 | "http://[1080::8:800:200C:417A]/foo", |
| 151 | "http://[2010:836B:4179::836B:4179]", |
| 152 | "http://[3ffe:2a00:100:7031::1]", |
| 153 | "http://[::192.9.5.5]/ipng", |
| 154 | "http://[::1]a/", |
| 155 | "http://[::FFFF:129.144.52.38]:80/index.html", |
| 156 | "http://[FEDC:AA98:7654:3210:FEDC:AA98:7654:3210]:80/index.html", |
| 157 | "http://[xyz]/", |
| 158 | "http://]/", |
| 159 | "http://a.example/?AZaz\ue000\uf8ffÀÖØöø˿ͰͽͿ\u1fff\u200c\u200d⁰\u218fⰀ\u2fef、\ud7ff﨎﷏ﷰ\uffef", |
| 160 | "http://a.example/AZazÀÖØöø˿ͰͽͿ\u1fff\u200c\u200d⁰\u218fⰀ\u2fef、\ud7ff﨎﷏ﷰ\uffef", |
| 161 | "http://a/?\ue000", |
| 162 | "http://example.123./aaa/bbb#ccc", |
| 163 | "http://example.comhttp://example.com#toto", |
| 164 | "http://example.com/", |
| 165 | "http://example.com/#toto", |
| 166 | "http://example.com/#\ue000", |
| 167 | "http://example.com//a", |
| 168 | "http://example.com/:", |
| 169 | "http://example.com/a", |
| 170 | "http://example.com/bar", |
| 171 | "http://example.com/bar/baz", |
| 172 | "http://example.com/foo", |
| 173 | "http://example.com/foo#bar", |
| 174 | "http://example.com/foo#baz", |
| 175 | "http://example.com/foo#toto", |
| 176 | "http://example.com/foo/", |
| 177 | "http://example.com/foo/bar", |
| 178 | "http://example.com/foo/bar#toto", |
| 179 | "http://example.com/foo/bar/", |
| 180 | "http://example.com/foo/bar/#toto", |
| 181 | "http://example.com/foo/bar/.././baz", |
| 182 | "http://example.com/foo/bar/?q=1&r=2", |
| 183 | "http://example.com/foo/bar/?q=1&r=2#toto", |
| 184 | "http://example.com/foo/bar?bat", |
| 185 | "http://example.com/foo/bar?bat#baz", |
| 186 | "http://example.com/foo/bar?q=1&r=2", |
| 187 | "http://example.com/foo/bar?q=1&r=2#toto", |
| 188 | "http://example.com/foo/baz", |
| 189 | "http://example.com/foo?bar", |
| 190 | "http://example.com/foo?bat", |
| 191 | "http://example.com/foo?bat#baz", |
| 192 | "http://example.com/foo?bat#foo", |
| 193 | "http://example.com/foo?baz", |
| 194 | "http://example.com/foo?foo", |
| 195 | "http://example.com/foo?query", |
| 196 | "http://example.com/\ue000", |
| 197 | "http://example.com?bar", |
| 198 | "http://example.com?query", |
| 199 | "http://example.org", |
| 200 | "http://example.org./aaa/bbb#ccc", |
| 201 | "http://example.org/[2010:836B:4179::836B:4179]", |
| 202 | "http://example.org/aaa%2Fbbb#ccc", |
| 203 | "http://example.org/aaa%2fbbb#ccc", |
| 204 | "http://example.org/aaa/bbb#ccc", |
| 205 | "http://example.org/abc#[2010:836B:4179::836B:4179]", |
| 206 | "http://example.org/xxx/[qwerty]#a[b]", |
| 207 | "http://example.org:/aaa/bbb#ccc", |
| 208 | "http://example.org:80/aaa/bbb#ccc", |
| 209 | "http://example/Andrȷ", |
| 210 | "http://example/a/b#c/../d", |
| 211 | "http://example/a/b?c/../d", |
| 212 | "http://example/x/abc", |
| 213 | "http://w3c.org:80path1/path2", |
| 214 | "http://www yahoo.com", |
| 215 | "http://www.ietf.org/rfc/rfc2396.txt", |
| 216 | "http://www.yaho%6f.com", |
| 217 | "http://www.yahoo.com", |
| 218 | "http://www.yahoo.com#bottom", |
| 219 | "http://www.yahoo.com/", |
| 220 | "http://www.yahoo.com/hello world/", |
| 221 | "http://www.yahoo.com/hello%00world/", |
| 222 | "http://www.yahoo.com/hello%20world/", |
| 223 | "http://www.yahoo.com/hello+world/", |
| 224 | "http://www.yahoo.com/stuff", |
| 225 | "http://www.yahoo.com/stuff/", |
| 226 | "http://www.yahoo.com/yelp.html#", |
| 227 | 'http://www.yahoo.com/yelp.html#"', |
| 228 | "http://www.yahoo.com/yelp.html#bottom", |
| 229 | "http://www.yahoo.com?name=%00%01", |
| 230 | "http://www.yahoo.com?name=obi", |
| 231 | "http://www.yahoo.com?name=obi&", |
| 232 | "http://www.yahoo.com?name=obi&type=", |
| 233 | "http://www.yahoo.com?name=obi+wan&status=jedi", |
| 234 | "http://www.yahoo.com?onery", |
| 235 | "http:/path", |
| 236 | "http:?foo", |
| 237 | "http:?query", |
| 238 | "http:g", |
| 239 | "http:this", |
| 240 | "https:", |
| 241 | "https://www.yahoo.com/", |
| 242 | "ldap://[2001:db8::7]/c=GB?objectClass?one", |
| 243 | "lv2.h", |
| 244 | "mailto:[email protected]", |
| 245 | "mailto:[email protected]", |
| 246 | "mailto:[email protected]#frag", |
| 247 | "mailto:user@host?subject=blah", |
| 248 | "mini1.xml", |
| 249 | "news:comp.infosystems.www.servers.unix", |
| 250 | "q%3Ar", |
| 251 | "q/r", |
| 252 | "q/r#", |
| 253 | "q/r#s", |
| 254 | "q/r#s/t", |
| 255 | "s", |
| 256 | "t:e/e/p", |
| 257 | "t:e/s", |
| 258 | "tel:+1-816-555-1212", |
| 259 | "telnet://192.0.2.16:80/", |
| 260 | "urn:", |
| 261 | "urn:.", |
| 262 | "urn:ab", |
| 263 | "urn:is/bn:foo", |
| 264 | "urn:isbn:foo", |
| 265 | "urn:oasis:names:specification:docbook:dtd:xml:4.1.2", |
| 266 | "x:", |
| 267 | "x://foo", |
| 268 | "x:02", |
| 269 | "x:?foo", |
| 270 | "y/z", |
| 271 | "y?q", |
| 272 | "z/", |
| 273 | "\ue000", |
| 274 | ".///C:::" |
| 275 | ] |
| 276 | example_pairs = [f"{e1}\0{e2}" for e1 in examples for e2 in examples] |
| 277 | |
| 278 | |
| 279 | def write_corpus(name, examples): |
| 280 | corpus_dir = Path("corpus") / name |
| 281 | corpus_dir.mkdir(parents=True, exist_ok=True) |
| 282 | for l in examples: |
| 283 | hash = hashlib.sha256() |
| 284 | hash.update(l.encode()) |
| 285 | (corpus_dir / hash.hexdigest()).write_text(l) |
| 286 | |
| 287 | |
| 288 | write_corpus("parse", examples) |
| 289 | write_corpus("resolve", example_pairs) |
| 290 | write_corpus("relativize", example_pairs) |