diff src/scriptcheck.sml @ 695:500e93aa436f

sleep and better Scriptcheck
author Adam Chlipala <adamc@hcoop.net>
date Sat, 04 Apr 2009 15:56:47 -0400
parents 655bcc9b77e0
children 6fc633d990e7
line wrap: on
line diff
--- a/src/scriptcheck.sml	Sat Apr 04 14:55:36 2009 -0400
+++ b/src/scriptcheck.sml	Sat Apr 04 15:56:47 2009 -0400
@@ -45,8 +45,7 @@
                              "self"])
                 
 val scriptWords = ["<script",
-                   " onclick=",
-                   " onload="]
+                   " onclick='"]
 
 val pushWords = ["rv("]
 
@@ -59,8 +58,15 @@
                 not (Substring.isEmpty suffix)
             end
 
-        fun hasClient {basis, words} csids =
+        fun hasClient {basis, words, onload} csids =
             let
+                fun realOnload ss =
+                    case ss of
+                        [] => false
+                      | (EFfiApp ("Basis", "get_settings", _), _) :: ss => realOnload ss
+                      | (EPrim (Prim.String s), _) :: ss => not (String.isPrefix "'" s)
+                      | _ => true
+
                 fun hasClient e =
                     case #1 e of
                         EPrim (Prim.String s) => List.exists (fn n => inString {needle = n, haystack = s}) words
@@ -73,6 +79,11 @@
                       | ESome (_, e) => hasClient e
                       | EFfi ("Basis", x) => SS.member (basis, x)
                       | EFfi _ => false
+                      | EFfiApp ("Basis", "strcat", all as ((EPrim (Prim.String s1), _) :: ss)) =>
+                        if onload andalso String.isSuffix " onload='" s1 then
+                            realOnload ss orelse List.exists hasClient all
+                        else
+                            List.exists hasClient all
                       | EFfiApp ("Basis", x, es) => SS.member (basis, x)
                                                     orelse List.exists hasClient es
                       | EFfiApp (_, _, es) => List.exists hasClient es
@@ -97,8 +108,8 @@
 
         fun decl ((d, _), (pull_ids, push_ids)) =
             let
-                val hasClientPull = hasClient {basis = pullBasis, words = scriptWords} pull_ids
-                val hasClientPush = hasClient {basis = pushBasis, words = pushWords} push_ids
+                val hasClientPull = hasClient {basis = pullBasis, words = scriptWords, onload = true} pull_ids
+                val hasClientPush = hasClient {basis = pushBasis, words = pushWords, onload = false} push_ids
             in
                 case d of
                     DVal (_, n, _, e) => (if hasClientPull e then