comparison src/scriptcheck.sml @ 645:1b571a05874c

React demo
author Adam Chlipala <adamc@hcoop.net>
date Tue, 10 Mar 2009 11:18:01 -0400
parents aa2290c32ce2
children b0c1a46b1f15
comparison
equal deleted inserted replaced
644:8e17e6b615bd 645:1b571a05874c
36 structure IS = IntBinarySet 36 structure IS = IntBinarySet
37 37
38 val csBasis = SS.addList (SS.empty, 38 val csBasis = SS.addList (SS.empty,
39 ["new_client_source", 39 ["new_client_source",
40 "get_client_source", 40 "get_client_source",
41 "set_client_source", 41 "set_client_source"])
42 "alert"]) 42
43 val scriptWords = ["<script",
44 " onclick="]
43 45
44 fun classify (ds, ps) = 46 fun classify (ds, ps) =
45 let 47 let
46 fun inString {needle, haystack} = 48 fun inString {needle, haystack} =
47 let 49 let
52 54
53 fun hasClient csids = 55 fun hasClient csids =
54 let 56 let
55 fun hasClient e = 57 fun hasClient e =
56 case #1 e of 58 case #1 e of
57 EPrim (Prim.String s) => inString {needle = "<script", haystack = s} 59 EPrim (Prim.String s) => List.exists (fn n => inString {needle = n, haystack = s}) scriptWords
58 | EPrim _ => false 60 | EPrim _ => false
59 | ERel _ => false 61 | ERel _ => false
60 | ENamed n => IS.member (csids, n) 62 | ENamed n => IS.member (csids, n)
61 | ECon (_, _, NONE) => false 63 | ECon (_, _, NONE) => false
62 | ECon (_, _, SOME e) => hasClient e 64 | ECon (_, _, SOME e) => hasClient e