Repository navigation
Expand file tree
/
Copy pathtesturi.cs
More file actions
78 lines (62 loc) · 2.37 KB
/
Copy pathtesturi.cs
File metadata and controls
78 lines (62 loc) · 2.37 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
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
using Newtonsoft.Json;
public class Output {
public string useragent;
public List<Dictionary<string, string>> constructor;
}
class testuri {
static void Main(string[] args) {
var text = System.IO.File.ReadAllText(args[0], Encoding.UTF8);
List<Dictionary<string, string>> tests =
JsonConvert.DeserializeObject<List<Dictionary<string, string>>>(text);
var constructors = new List<Dictionary<string, string>>();
foreach (var test in tests) {
var result = new Dictionary<string, string>();
result["input"] = test["input"];
result["base"] = test["base"];
try {
var base_uri = new Uri((string)test["base"]);
var uri = new Uri(base_uri, (string)test["input"]);
result["href"] = uri.ToString();
result["protocol"] = uri.Scheme + ":";
if (uri.UserInfo != "") {
var parts = uri.UserInfo.Split(":".ToCharArray(), 2);
result["username"] = parts[0];
if (parts.Length > 1) result["password"] = parts[1];
}
result["hostname"] = uri.Host;
if (!uri.IsDefaultPort && uri.Port != -1) {
result["port"] = uri.Port.ToString();
}
result["pathname"] = String.Join("", uri.Segments);
if (uri.Query != "") {
result["search"] = uri.Query;
}
if (uri.Fragment != "") {
// See http://www.ietf.org/mail-archive/web/apps-discuss/current/msg13721.html
// result["hash"] = uri.Fragment;
result["hash"] = '#' + uri.GetComponents(UriComponents.Fragment,
UriFormat.Unescaped);
}
} catch(System.UriFormatException e) {
result["exception"] = e.Message;
result["href"] = (string)test["input"];
result["protocol"] = ":";
}
constructors.Add(result);
}
var output = new Output();
var assembly = Assembly.GetExecutingAssembly();
foreach (var name in assembly.GetReferencedAssemblies()) {
if (name.Name == "System") {
output.useragent = name.ToString();
}
}
output.constructor = constructors;
var json = JsonConvert.SerializeObject(output, Formatting.Indented);
System.IO.File.WriteAllText(args[1], json, new UTF8Encoding(false));
}
}