diff lib/js/urweb.js @ 1323:0d8bd8ae8417

Fix JavaScript unit unurlification; URL blessing client-side
author Adam Chlipala <adamc@hcoop.net>
date Fri, 26 Nov 2010 11:57:04 -0500
parents 6791454653c5
children 02fc16faecf3
line wrap: on
line diff
--- a/lib/js/urweb.js	Sun Nov 21 15:43:24 2010 -0500
+++ b/lib/js/urweb.js	Fri Nov 26 11:57:04 2010 -0500
@@ -1182,5 +1182,26 @@
 }
 
 
+// URL blessing
+
+var urlRules = null;
+
+function checkUrl(s) {
+    for (var r = urlRules; r; r = r.next) {
+        var ru = r.data;
+        if (ru.prefix ? s.indexOf(ru.pattern) == 0 : s == ru.pattern)
+            return ru.allow ? s : null;
+    }
+
+    return null;
+}
+
+function bless(s) {
+    u = checkUrl(s);
+    if (u == null)
+        er("Disallowed URL: " + s);
+    return u;
+}
+
 // App-specific code