6
6
import org .junit .Test ;
7
7
import org .junit .runner .RunWith ;
8
8
9
+ import static java .lang .String .format ;
9
10
import static org .hamcrest .MatcherAssert .assertThat ;
10
11
import static org .hamcrest .Matchers .is ;
11
12
@@ -19,16 +20,26 @@ public class XSSApiTest {
19
20
public static Object [][] links () {
20
21
return new Object [][]{
21
22
new Object []{"javascript:alert(1);//" , "" },
23
+ new Object []{"javascript:alert(1)://" , "" },
22
24
new Object []{"http://abcxyz.com?a=b&c=d';alert(1);//" , "http://abcxyz.com?a=b&c=d';alert(1);//" },
23
25
new Object []{"http://github.com/bla/bla" , "http://github.com/bla/bla" },
24
26
new Object []{"https://github.com/bla/bla" , "https://github.com/bla/bla" },
25
- new Object []{"https://company.com/bla" , "https://company.com/bla" }
27
+ new Object []{"https://company.com/bla" , "https://company.com/bla" },
28
+ new Object []{"/company.com/bla" , "" },
29
+ new Object []{"//" , "" },
30
+ new Object []{"//text" , "" },
31
+ new Object []{"//text/" , "" },
32
+ new Object []{"ftp://" , "ftp:" },
33
+ new Object []{"ftp://a" , "ftp://a" },
34
+ new Object []{"text" , "" },
35
+ new Object []{"github.com/bla/bla" , "" },
36
+ new Object []{"http://127.0.0.1/" , "http://127.0.0.1/" },
26
37
};
27
38
}
28
39
29
40
@ Test
30
41
@ UseDataProvider ("links" )
31
42
public void shouldSanitizeUrl (String url , String expected ) throws Exception {
32
- assertThat (XSSApi .asValidHref (url ), is (expected ));
43
+ assertThat (format ( "For %s" , url ), XSSApi .asValidHref (url ), is (expected ));
33
44
}
34
45
}
0 commit comments