chriswarbo-net: 1cf0d9cef53d2d1eda15d9728940e28a79032bc4
1: { commands, runCommand, withDeps, writeScript, xidel }:
2:
3: with builtins;
4: with rec {
5: relToTest = runCommand "relative" {
6: buildInputs = [ xidel ];
7: page = relToUntested "." (writeScript "test.html" ''
8: <html>
9: <head>
10: <link rel="stylesheet" type="text/css"
11: href="/css/default.css" />
12: <meta http-equiv="refresh" content="0;URL=./projects.html" />
13: </head>
14: <body>
15: <a href="/blog.html">Blog</a>
16: <script src="/js/foo.js"></script>
17: <img src="/images/foo.png" />
18: </body>
19: </html>
20: '');
21: } ''
22: set -e
23:
24: function fail() {
25: echo "Found absolute paths in $1" 1>&2
26: exit 1
27: }
28:
29: for PAIR in '//a/@href anchors' \
30: '//link/@href links' \
31: '//script/@src scripts' \
32: '//img/@src images' \
33: '//meta/@content meta'
34: do
35: QUERY=$(echo "$PAIR" | cut -f1)
36: TYPE=$(echo "$PAIR" | cut -f2)
37: FOUND=$(xidel -s -e "$QUERY" - < "$page")
38:
39: echo "$FOUND" | grep "^/" || continue
40: echo "$FOUND" | grep "=/" || continue
41: fail "$TYPE"
42: done
43:
44: if grep 'var url = "/' < "$page"
45: then
46: fail "script vars"
47: fi
48:
49: mkdir "$out"
50: '';
51:
52: relToUntested = TO_ROOT: file:
53: runCommand "relative-${baseNameOf (unsafeDiscardStringContext file)}" {
54: inherit file TO_ROOT;
55: buildInputs = [ commands.relativise ];
56: } ''
57: echo "Relativising $file to $TO_ROOT" 1>&2
58: relativise < "$file" > "$out"
59: '';
60: };
61: x: y:
62: withDeps [ relToTest ] (relToUntested x y)
Generated by git2html.