forked from phcode-dev/staging.phcode.dev
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathparse.html
More file actions
82 lines (74 loc) · 2.35 KB
/
parse.html
File metadata and controls
82 lines (74 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Parse Tests</title>
<script src="../path-utils.min.js"></script>
</head>
<body>
<pre>
<script>
function entityEncode( str )
{
return ( str || "" ).replace(/&/, "&").replace(/</, "<").replace(/>/, ">");
}
function getMaxLength( arr )
{
var i, max = 0;
for ( i = 0; i < arr.length; i++ ) {
max = Math.max( max, ( arr[ i ] || "" ).length );
}
return max;
}
function getSpaces( num )
{
var i, result = "";
num = num < 1 ? 0 : num;
for ( i = 0; i < num; i++) {
result += " ";
}
return result;
}
var testUrls = [
"http://jblas:password@mycompany.com:8080/mail/inbox?msg=1234&type=unread#msg-content",
"//jblas:password@mycompany.com:8080/mail/inbox?msg=1234&type=unread#msg-content",
"//mycompany.com:8080/mail/inbox?msg=1234&type=unread#msg-content",
"/mail/inbox?msg=1234&type=unread#msg-content",
"mail/inbox?msg=1234&type=unread#msg-content",
"inbox?msg=1234&type=unread#msg-content",
"?msg=1234&type=unread#msg-content",
"#msg-content",
"http://mycompany.com/mail/inbox?msg=1234&type=unread#msg-content",
"//mycompany.com/mail/inbox?msg=1234&type=unread#msg-content",
"/mail/inbox?msg=1234&type=unread#msg-content",
"mail/inbox?msg=1234&type=unread#msg-content",
"inbox?msg=1234&type=unread#msg-content",
"http://jblas:password@123.456.78.9:8080/mail/inbox?msg=1234&type=unread#msg-content",
"//jblas:password@123.456.78.9:8080/mail/inbox?msg=1234&type=unread#msg-content",
"//123.456.78.9:8080/mail/inbox?msg=1234&type=unread#msg-content",
"http://mycompany.com/a/b.php?foo=1&bar=2",
"http://mycompany.com/b.php?foo=1&bar=2",
"http://mycompany.com/a/b.html",
"http://mycompany.com/b.html",
"a/file.html",
"/file.html",
"file.html",
"../file.html",
"a/b/../../file.html",
"http://mycompany.com/a/b-1.0-min.js?foo=1&bar=2"
],
props = PathUtils.parsedUrlPropNames,
maxLen = getMaxLength( props ),
obj;
for ( var i = 0; i < testUrls.length; i++ ) {
document.write("<strong>Url:</strong> " + entityEncode( testUrls[ i ] ) + "\n\n");
obj = PathUtils.parseUrl( testUrls[ i ] );
for ( var j = 0; j < props.length; j++ ) {
document.write("\t<strong>" + getSpaces( maxLen - props[ j ].length ) + props[ j ] + ":</strong> " + entityEncode( obj[ props[ j ] ] ) + "\n");
}
document.write("\n\n");
}
</script>
</pre>
</body>
</html>