]> gitweb.factorcode.org Git - factor.git/commitdiff
farkup,webbrowser: better url validation
authorBjörn Lindqvist <bjourne@gmail.com>
Sun, 18 Dec 2016 01:58:04 +0000 (02:58 +0100)
committerBjörn Lindqvist <bjourne@gmail.com>
Sun, 18 Dec 2016 01:58:04 +0000 (02:58 +0100)
basis/farkup/farkup.factor
basis/webbrowser/webbrowser-tests.factor
basis/webbrowser/webbrowser.factor

index a3d79adfb3b5cfe1539fa2d924ef0fcf978baa89..4107bb7d16bead719fc8e6bf52850d98b9326df3 100644 (file)
@@ -1,9 +1,9 @@
 ! Copyright (C) 2008, 2009 Doug Coleman, Daniel Ehrenberg.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: sequences kernel splitting lists fry accessors assocs math.order
-math combinators namespaces urls.encoding xml.syntax xmode.code2html
-xml.data arrays strings vectors xml.writer io.streams.string locals
-unicode ;
+USING: accessors arrays assocs combinators fry io.streams.string
+kernel lists locals math math.order namespaces sequences splitting
+strings urls urls.encoding xml.data xml.syntax xml.writer
+xmode.code2html ;
 IN: farkup
 
 SYMBOL: relative-link-prefix
@@ -33,7 +33,7 @@ TUPLE: line ;
 TUPLE: line-break ;
 
 : absolute-url? ( string -- ? )
-    { "http://" "https://" "ftp://" } [ head? ] with any? ;
+    >url protocol>> >boolean ;
 
 : simple-link-title ( string -- string' )
     dup absolute-url? [ "/" split1-last swap or ] unless ;
index 5e95d40199efaf29c264aa9220acf5f3b4191c4b..e667e35c0ec90abb61f1f0e228877d91a5f31a0c 100644 (file)
@@ -3,5 +3,6 @@ IN: webbrowser
 
 { t } [ "http://reddit.com" url-string? ] unit-test
 { t } [ "https://reddit.com" url-string? ] unit-test
-{ f } [ "ftp://reddit.com" url-string? ] unit-test
+{ t } [ "ftp://reddit.com" url-string? ] unit-test
+{ f } [ "moo" url-string? ] unit-test
 { f } [ 123 url-string? ] unit-test
index 7553989ecdf957a3218c3e508b87a15abbd810ef..2bcfccb5882a19b9a8307233e7c487c83da4fb26 100644 (file)
@@ -1,8 +1,8 @@
 ! Copyright (C) 2011 John Benediktsson
 ! See http://factorcode.org/license.txt for BSD license
 
-USING: accessors combinators.short-circuit io.pathnames
-sequences strings system ui.operations urls vocabs ;
+USING: accessors io.pathnames kernel sequences strings system
+ui.operations urls vocabs ;
 
 IN: webbrowser
 
@@ -17,7 +17,6 @@ HOOK: open-file os ( path -- )
 
 [ url? ] \ open-url H{ } define-operation
 
-PREDICATE: url-string < string
-    { [ "http://" head? ] [ "https://" head? ] } 1|| ;
+PREDICATE: url-string < string >url protocol>> >boolean ;
 
 [ url-string? ] \ open-url H{ } define-operation