| 960 | } |
| 961 | |
| 962 | func TestHTTPURL(t *testing.T) { |
| 963 | tests := []struct { |
| 964 | name string |
| 965 | value string |
| 966 | want string |
| 967 | wantOK bool |
| 968 | }{ |
| 969 | { |
| 970 | name: "an https URL", |
| 971 | value: "https://github.com/monalisa/monas-cafe/wiki/OAuth-runbook", |
| 972 | want: "https://github.com/monalisa/monas-cafe/wiki/OAuth-runbook", |
| 973 | wantOK: true, |
| 974 | }, |
| 975 | { |
| 976 | name: "an http URL with a port, query and fragment", |
| 977 | value: "http://staging.monas-cafe.example:8080/menu?day=monday#specials", |
| 978 | want: "http://staging.monas-cafe.example:8080/menu?day=monday#specials", |
| 979 | wantOK: true, |
| 980 | }, |
| 981 | { |
| 982 | name: "surrounding whitespace is trimmed", |
| 983 | value: " \thttps://github.com/monalisa/monas-cafe/wiki/OAuth-runbook\r\n", |
| 984 | want: "https://github.com/monalisa/monas-cafe/wiki/OAuth-runbook", |
| 985 | wantOK: true, |
| 986 | }, |
| 987 | { |
| 988 | name: "an uppercase scheme", |
| 989 | value: "HTTPS://github.com/monalisa/monas-cafe", |
| 990 | want: "HTTPS://github.com/monalisa/monas-cafe", |
| 991 | wantOK: true, |
| 992 | }, |
| 993 | { |
| 994 | name: "another scheme", |
| 995 | value: "ftp://monas-cafe.example/menu.pdf", |
| 996 | }, |
| 997 | { |
| 998 | name: "a script", |
| 999 | value: "javascript:alert(1)", |
| 1000 | }, |
| 1001 | { |
| 1002 | name: "a local file", |
| 1003 | value: "file:///etc/hosts", |
| 1004 | }, |
| 1005 | { |
| 1006 | name: "no host", |
| 1007 | value: "https:///monalisa/monas-cafe", |
| 1008 | }, |
| 1009 | { |
| 1010 | name: "no slashes after the scheme", |
| 1011 | value: "https:github.com/monalisa/monas-cafe", |
| 1012 | }, |
| 1013 | { |
| 1014 | name: "a relative URL", |
| 1015 | value: "/monalisa/monas-cafe/wiki/OAuth-runbook", |
| 1016 | }, |
| 1017 | { |
| 1018 | name: "a space inside", |
| 1019 | value: "https://github.com/monalisa/monas cafe", |