From 99fdcac63e9a5a55a95c31ef569f025d2f25876d Mon Sep 17 00:00:00 2001 From: Adam Chlipala Date: Fri, 26 Nov 2010 11:57:04 -0500 Subject: Fix JavaScript unit unurlification; URL blessing client-side --- lib/js/urweb.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'lib') diff --git a/lib/js/urweb.js b/lib/js/urweb.js index 8ca6b89c..f98476b7 100644 --- a/lib/js/urweb.js +++ b/lib/js/urweb.js @@ -1182,5 +1182,26 @@ function confrm(s) { } +// 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 -- cgit v1.2.3