farkup,webbrowser: better url validation
parent
20a98a38fb
commit
88015e9632
|
@ -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 ;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue