Annotation of parser3/tests/459.html, revision 1.1

1.1     ! moko        1: # file:// disk paths, and schemes allowed per call site (feature #941)
        !             2: # No absolute path is reported: it is machine dependent, and outside windows ':' gets escaped on untaint.
        !             3: @main[][root;uri;dir;text]
        !             4: $root[$request:document-root]
        !             5: $uri[^file_uri[$root/tests/459.html]]
        !             6: $dir[^file_uri[$root/tests]]
        !             7: 
        !             8: $report[^hash::create[]]
        !             9: 
        !            10: # these do not depend on document-root
        !            11: $report.schemes[
        !            12:        $.[load parser://][ ^outcome{ $f[^file::load[text;parser://method]] $f.text }]
        !            13:        $.[load http:// is allowed][ ^allowed{ $f[^file::load[text;http://127.0.0.1:1/x]] }]
        !            14:        $.[table::load http:// is allowed][ ^allowed{ $t[^table::load[http://127.0.0.1:1/x]] }]
        !            15:        $.[table::load file://][ ^outcome{ $t[^table::load[nameless;$uri]] ^if(^t.count[]){loaded}{EMPTY} }]
        !            16:        $.[fullpath http://][ ^outcome{ ^file:fullpath[http://example.com/some/long/path.gif] }]
        !            17:        $.[a built uri keeps the scheme][ ^outcome{ ^file:fullpath[http://$root/path.gif] }]
        !            18:        $.[scheme only at the start][ ^outcome{ ^file:fullpath[x/file:///etc/passwd] }]
        !            19:        $.[other authority rejected][ ^outcome{ ^file:fullpath[file://evilhost/nonexistent] }]
        !            20:        $.[empty file:// rejected][ ^outcome{ ^file:fullpath[file://] }]
        !            21:        $.[use file://][ ^outcome{ ^use[^file_uri[$root/tests/366.p]] used }]
        !            22:        $.[use http://][ ^outcome{ ^use[http://127.0.0.1:1/x.p] }]
        !            23:        $.[windows-only file://C:/ form][ ^if(^root.left(1) eq '/'){ok}{ ^eq[ ^outcome{ ^file:fullpath[file://$root/tests/459.html] }; /tests/459.html ] }]
        !            24: ]
        !            25: 
        !            26: # where a uri is an error, and where it is just no file
        !            27: $report.throwing[
        !            28:        $.[save refuses a uri][ ^outcome{ $s[text] ^s.save[http://example.com/459.txt] }]
        !            29:        $.[save refuses an invalid file://][ ^outcome{ $s[text] ^s.save[file://evilhost/459.txt] }]
        !            30:        $.[delete refuses a uri][ ^outcome{ ^file:delete[http://example.com/459.txt] }]
        !            31:        $.[delete with exception(false) ignores a uri][ ^outcome{ ^file:delete[http://example.com/459.txt][ $.exception(false) ] silent }]
        !            32:        $.[delete with exception(false) ignores an invalid file://][ ^outcome{ ^file:delete[file://evilhost/459.txt][ $.exception(false) ] silent }]
        !            33:        $.[find never finds a uri][ ^outcome{ ^file:find[http://example.com/Makefile]{not found} }]
        !            34:        $.[find does not throw on an invalid file://][ ^outcome{ ^file:find[file://evilhost/Makefile]{not found} }]
        !            35:        $.[-f and -d do not throw on a uri or an invalid file://][ ^outcome{ ^if(-f 'http://example.com/x' || -d 'parser://x' || -f 'file://evilhost/x'){YES}{no} }]
        !            36:        $.[-f and -d accept file://][ ^outcome{ ^if(-f $uri && -d $dir){yes}{NO} }]
        !            37: ]
        !            38: 
        !            39: # the same checks against three flavours of document-root
        !            40: $report.[document-root][
        !            41:        $.plain[ ^cycle[$root;$root] ]
        !            42:        $.[with a trailing slash][ ^cycle[$root/;$root] ]
        !            43:        $.empty[ ^cycle[;$root] ]
        !            44: ]
        !            45: 
        !            46: # last, as it changes document-root too: /root must not match /rootbeer
        !            47: $request:document-root[$root/tes]
        !            48: $report.[segment boundary][
        !            49:        $.[disk path][ ^outcome{ ^file:fullpath[$uri] }]
        !            50:        $.[relative name][ ^outcome{ ^file:fullpath[x.gif] }]
        !            51: ]
        !            52: 
        !            53: # the document root is machine dependent
        !            54: $text[^print[$report]]
        !            55: ^taint[as-is][^text.replace[$root;<root>]]
        !            56: 
        !            57: 
        !            58: @cycle[root;root0][web;prefix;uri;luri;found;deep]
        !            59: $request:document-root[$root]
        !            60: # with no root a disk path is its own web path, but only one starting with '/', not so under windows:
        !            61: # hence the comparisons below instead of just the result
        !            62: $web(def $root || ^root0.left(1) eq '/')
        !            63: $prefix[^if(def $root){}{$root0}]
        !            64: $uri[^file_uri[$root0/tests/459.html]]
        !            65: $luri[^file_uri[$root0/tests/459.html;localhost]]
        !            66: # test.p has no namesake up the tree, so a mangled path would not be found by climbing up by chance
        !            67: $found[^file_uri[$root0/tests/366_dir/test.p]]
        !            68: $deep[^file_uri[$root0/tests/366_dir/zz/test.p]]
        !            69: $result[
        !            70:        $.[file:// loads the same file][ ^outcome{ $a[^file::load[text;$uri]] ^if(^a.text.length[]){loaded}{EMPTY} }]
        !            71:        $.[fullpath of a relative name][ ^eq[ ^outcome{ ^file:fullpath[x.gif] }; ^if($web){$prefix/tests/x.gif}{Exception: is outside of ^$request:document-root []} ]]
        !            72:        $.[fullpath maps file:// to web space][ ^eq[ ^outcome{ ^file:fullpath[$uri] }; ^if($web){$prefix/tests/459.html}{Exception: is outside of ^$request:document-root []} ]]
        !            73:        $.[fullpath maps file://localhost/ to web space][ ^eq[ ^outcome{ ^file:fullpath[$luri] }; ^if($web){$prefix/tests/459.html}{Exception: is outside of ^$request:document-root []} ]]
        !            74:        $.[find maps file:// to web space][ ^eq[ ^file:find[$found]{NOT FOUND}; ^if($web){$prefix/tests/366_dir/test.p}{NOT FOUND} ]]
        !            75:        $.[find climbs up from a disk path][ ^eq[ ^file:find[$deep]{NOT FOUND}; ^if($web){$prefix/tests/366_dir/test.p}{NOT FOUND} ]]
        !            76:        $.[find climbs up from a web path][ ^file:find[/tests/zz/Makefile]{NOT FOUND}]
        !            77:        $.[find relative to the request uri][ ^file:find[Makefile]{NOT FOUND}]
        !            78:        $.[localhost authority allowed][ ^outcome{ ^file:fullpath[file://localhost/nonexistent-459] }]
        !            79:        $.[fullpath outside the root][ ^outcome{ ^file:fullpath[file:///nonexistent-459] }]
        !            80:        $.[find outside the root][ ^file:find[file:///nonexistent-459]{NOT FOUND}]
        !            81: ]
        !            82: 
        !            83: @print[h;indent][k;v]
        !            84: ^h.foreach[k;v]{${indent}${k}:^if($v is 'hash'){^#0A^print[$v;$indent^#09]}{ ^v.trim[]^#0A}}
        !            85: 
        !            86: @outcome[code]
        !            87: ^try{
        !            88:        $result[$code]
        !            89:        $result[^result.trim[]]
        !            90: }{
        !            91:        $exception.handled(true)
        !            92:        $result[Exception: $exception.comment]
        !            93: }
        !            94: 
        !            95: # a scheme is allowed when the attempt fails anyhow, but not as an unsupported one
        !            96: @allowed[code][r]
        !            97: $r[^outcome{$code}]
        !            98: $result[^if(^r.pos[unsupported path scheme]>=0){REJECTED}{allowed}]
        !            99: 
        !           100: # a standard file uri: file:///C:/path or file://localhost/C:/path under windows
        !           101: @file_uri[path;host]
        !           102: $result[file://$host^if(^path.left(1) ne '/'){/}$path]
        !           103: 
        !           104: @eq[got;want]
        !           105: $result[^if(^got.trim[] eq ^want.trim[]){ok}{WRONG [$got] want [$want]}]

E-mail: